vue.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title || '机柜管理系统'
  8. const port = process.env.port || process.env.npm_config_port || 9101 // dev port
  9. module.exports = {
  10. publicPath: '/',
  11. outputDir: 'dist',
  12. assetsDir: 'static',
  13. lintOnSave: false,
  14. productionSourceMap: false,
  15. devServer: {
  16. port: port,
  17. open: true,
  18. overlay: {
  19. warnings: false,
  20. errors: true
  21. },
  22. proxy: {
  23. '/api': {
  24. target: 'http://localhost:9100',
  25. pathRewrite: { '^/api': '' }
  26. }
  27. }
  28. },
  29. configureWebpack: {
  30. name: name,
  31. resolve: {
  32. alias: {
  33. '@': resolve('src')
  34. }
  35. }
  36. },
  37. chainWebpack(config) {
  38. config.plugins.delete('preload')
  39. config.plugins.delete('prefetch')
  40. config.module
  41. .rule('svg')
  42. .exclude.add(resolve('src/icons'))
  43. .end()
  44. config.module
  45. .rule('icons')
  46. .test(/\.svg$/)
  47. .include.add(resolve('src/icons'))
  48. .end()
  49. .use('svg-sprite-loader')
  50. .loader('svg-sprite-loader')
  51. .options({
  52. symbolId: 'icon-[name]'
  53. })
  54. .end()
  55. config.module
  56. .rule('vue')
  57. .use('vue-loader')
  58. .loader('vue-loader')
  59. .tap(options => {
  60. options.compilerOptions.preserveWhitespace = true
  61. return options
  62. })
  63. .end()
  64. config
  65. .when(process.env.NODE_ENV === 'development',
  66. config => config.devtool('cheap-source-map')
  67. )
  68. config
  69. .when(process.env.NODE_ENV !== 'development',
  70. config => {
  71. config
  72. .plugin('ScriptExtHtmlWebpackPlugin')
  73. .after('html')
  74. .use('script-ext-html-webpack-plugin', [{
  75. inline: /runtime\..*\.js$/
  76. }])
  77. .end()
  78. config
  79. .optimization.splitChunks({
  80. chunks: 'all',
  81. cacheGroups: {
  82. libs: {
  83. name: 'chunk-libs',
  84. test: /[\\/]node_modules[\\/]/,
  85. priority: 10,
  86. chunks: 'initial'
  87. },
  88. elementUI: {
  89. name: 'chunk-elementUI',
  90. priority: 20,
  91. test: /[\\/]node_modules[\\/]_?element-ui(.*)/
  92. },
  93. commons: {
  94. name: 'chunk-commons',
  95. test: resolve('src/components'), // can customize your rules
  96. minChunks: 3,
  97. priority: 5,
  98. reuseExistingChunk: true
  99. }
  100. }
  101. })
  102. config.optimization.runtimeChunk('single')
  103. }
  104. )
  105. }
  106. }