vue.config.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 || 'ChargEco' // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  14. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  15. module.exports = {
  16. /**
  17. * You will need to set publicPath if you plan to deploy your site under a sub path,
  18. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  19. * then publicPath should be set to "/bar/".
  20. * In most cases please use '/' !!!
  21. * Detail: https://cli.vuejs.org/config/#publicpath
  22. */
  23. publicPath: process.env.ENV === 'development' ? '/csms' : '',
  24. outputDir: 'ChargEco-CSMS',
  25. assetsDir: 'static',
  26. lintOnSave: process.env.NODE_ENV === 'development',
  27. productionSourceMap: false,
  28. devServer: {
  29. port: port,
  30. open: true,
  31. overlay: {
  32. warnings: false,
  33. errors: true
  34. },
  35. },
  36. configureWebpack: {
  37. // provide the app's title in webpack's name field, so that
  38. // it can be accessed in index.html to inject the correct title.
  39. name: name,
  40. resolve: {
  41. alias: {
  42. '@': resolve('src')
  43. }
  44. },
  45. externals: {
  46. 'google': 'google'
  47. }
  48. },
  49. configureWebpack: config=> {
  50. if (process.env.NODE_ENV === 'production') {
  51. config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
  52. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  53. config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
  54. config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['__f__','console.log','console.error']
  55. }
  56. },
  57. chainWebpack(config) {
  58. // it can improve the speed of the first screen, it is recommended to turn on preload
  59. // it can improve the speed of the first screen, it is recommended to turn on preload
  60. config.plugin('preload').tap(() => [
  61. {
  62. rel: 'preload',
  63. // to ignore runtime.js
  64. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  65. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  66. include: 'initial'
  67. }
  68. ])
  69. // when there are many pages, it will cause too many meaningless requests
  70. config.plugins.delete('prefetch')
  71. // set svg-sprite-loader
  72. config.module
  73. .rule('svg')
  74. .exclude.add(resolve('src/icons'))
  75. .end()
  76. config.module
  77. .rule('icons')
  78. .test(/\.svg$/)
  79. .include.add(resolve('src/icons'))
  80. .end()
  81. .use('svg-sprite-loader')
  82. .loader('svg-sprite-loader')
  83. .options({
  84. symbolId: 'icon-[name]'
  85. })
  86. .end()
  87. config
  88. .when(process.env.NODE_ENV !== 'development',
  89. config => {
  90. config
  91. .plugin('ScriptExtHtmlWebpackPlugin')
  92. .after('html')
  93. .use('script-ext-html-webpack-plugin', [{
  94. // `runtime` must same as runtimeChunk name. default is `runtime`
  95. inline: /runtime\..*\.js$/
  96. }])
  97. .end()
  98. config
  99. .optimization.splitChunks({
  100. chunks: 'all',
  101. minSize: 20000,
  102. maxInitialRequests: Infinity,
  103. cacheGroups: {
  104. libs: {
  105. name: 'chunk-libs',
  106. test: /[\\/]node_modules[\\/]/,
  107. priority: 10,
  108. chunks: 'initial' // only package third parties that are initially dependent
  109. },
  110. elementUI: {
  111. name: 'chunk-theme', // split elementUI into a single package
  112. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  113. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  114. },
  115. vue: {
  116. name: 'chunk-vue',
  117. test: /[\\/]node_modules[\\/](vue|vuex|vue-router|veu-loader|axios|screenfull|qrcodejs2)/,
  118. priority: 30
  119. },
  120. echarts: {
  121. name: 'chunk-echarts',// split echarts libs
  122. test: /[\\/]node_modules[\\/](echarts)/,
  123. priority: 35
  124. },
  125. googlemaps: {
  126. name: 'chunk-googlemaps',// split others libs
  127. test: /[\\/]node_modules[\\/](clipboardy|core-js|js-base64|js-cookie|nprogress|@googlemaps)/,
  128. priority: 39
  129. },
  130. router: {
  131. name: 'chunk-router',
  132. test: /[\\/]src[\\/]views[\\/](charging|transaction|user|driver)/,
  133. priority: 40
  134. },
  135. commons: {
  136. name: 'chunk-commons',
  137. test: /[\\/]src[\\/]views[\\/](site|charge|ocpp|login)/, // can customize your rules
  138. priority: 41
  139. },
  140. vbea: {
  141. name: 'chunk-vbea',
  142. test: /[\\/]src[\\/]views[\\/](limit|feedback|financial|provider)/,
  143. priority: 42
  144. },
  145. index: {
  146. name: 'chunk-index',
  147. test: /[\\/]src[\\/]views[\\/](dashboard)/,
  148. priority: 44
  149. },
  150. assets: {
  151. name: 'chunk-assets',
  152. test: /[\\/]src[\\/](assets|icons)/,
  153. priority: 50
  154. },
  155. utils: {
  156. name: 'chunk-utils',
  157. test: /[\\/]src[\\/](utils|layout|store|router|components|http)/,
  158. priority: 51
  159. }
  160. }
  161. })
  162. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  163. config.optimization.runtimeChunk('single')
  164. }
  165. )
  166. }
  167. }