vue.config.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. 'use strict'
  2. const path = require('path')
  3. const FileManagerPlugin = require("filemanager-webpack-plugin");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. // If your port is set to 80,
  8. // use administrator privileges to execute the command line.
  9. // For example, Mac: sudo npm run
  10. // You can change the port by the following methods:
  11. // port = 9528 npm run dev OR npm run dev --port = 9528
  12. const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  13. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  14. module.exports = {
  15. /**
  16. * You will need to set publicPath if you plan to deploy your site under a sub path,
  17. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  18. * then publicPath should be set to "/bar/".
  19. * In most cases please use '/' !!!
  20. * Detail: https://cli.vuejs.org/config/#publicpath
  21. */
  22. publicPath: './',
  23. outputDir: 'dist/SzLivePlatformManageFront',
  24. assetsDir: 'static',
  25. lintOnSave: process.env.NODE_ENV === 'development',
  26. productionSourceMap: false,
  27. devServer: {
  28. port: port,
  29. open: true,
  30. overlay: {
  31. warnings: false,
  32. errors: true
  33. }
  34. },
  35. configureWebpack: config => {
  36. config.devServer = {
  37. proxy: {
  38. // "^/user": {target: "http://192.168.58.137:10086"},
  39. // "^/(user|goods|goodsTypes|order|orderItem|rooms|room)/": { target: "http://127.0.0.1:10086" },
  40. // "^/.*": { target: "http://116.63.32.160:8085" },
  41. "^/.*": { target: "http://127.0.0.1:10086" },
  42. },
  43. }
  44. if (process.env.NODE_ENV != 'development') {
  45. config.plugins.push(new FileManagerPlugin({
  46. events: {
  47. onStart: {
  48. delete: [`dist/SzLivePlatformManageFront`]
  49. },
  50. onEnd: {
  51. archive: [
  52. {
  53. source: `dist/SzLivePlatformManageFront`,
  54. destination: `dist/SzLivePlatformManageFront.zip`,
  55. format: 'zip',
  56. options: {
  57. gzip: true,
  58. gzipOptions: {
  59. level: 1
  60. },
  61. globOptions: {
  62. nomount: true
  63. }
  64. }
  65. }
  66. ]
  67. }
  68. }
  69. }))
  70. }
  71. },
  72. // configureWebpack: {
  73. // // provide the app's title in webpack's name field, so that
  74. // // it can be accessed in index.html to inject the correct title.
  75. // resolve: {
  76. // alias: {
  77. // '@': resolve('src')
  78. // }
  79. // },
  80. // devServer: {
  81. // proxy: {
  82. // // "^/user": {target: "http://192.168.58.137:10086"},
  83. // // "^/(user|goods|goodsTypes|order|orderItem|rooms|room)/": { target: "http://127.0.0.1:10086" },
  84. // // "^/.*": { target: "http://116.63.32.160:8085" },
  85. // "^/.*": { target: "http://127.0.0.1:10086" },
  86. // },
  87. // // plugins: process.env.NODE_ENV == 'production'? [
  88. // // new FileManagerPlugin({
  89. // // events: {
  90. // // onStart: {
  91. // // delete: [`dist/${page}`]
  92. // // },
  93. // // onEnd: {
  94. // // archive: [
  95. // // {
  96. // // source: `dist/SzLivePlatformManageFront`,
  97. // // destination: `dist/SzLivePlatformManageFront.zip`,
  98. // // format: 'zip',
  99. // // options: {
  100. // // gzip: true,
  101. // // gzipOptions: {
  102. // // level: 1
  103. // // },
  104. // // globOptions: {
  105. // // nomount: true
  106. // // }
  107. // // }
  108. // // }
  109. // // ]
  110. // // }
  111. // // }
  112. // // })
  113. // // ]: []
  114. // }
  115. // },
  116. chainWebpack(config) {
  117. // it can improve the speed of the first screen, it is recommended to turn on preload
  118. config.plugin('preload').tap(() => [
  119. {
  120. rel: 'preload',
  121. // to ignore runtime.js
  122. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  123. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  124. include: 'initial'
  125. }
  126. ])
  127. config.optimization.minimizer('terser').tap((args) => {
  128. args[0].terserOptions.compress.drop_console = true;
  129. return args;
  130. })
  131. // when there are many pages, it will cause too many meaningless requests
  132. config.plugins.delete('prefetch')
  133. // set svg-sprite-loader
  134. config.module
  135. .rule('svg')
  136. .exclude.add(resolve('src/icons'))
  137. .end()
  138. config.module
  139. .rule('icons')
  140. .test(/\.svg$/)
  141. .include.add(resolve('src/icons'))
  142. .end()
  143. .use('svg-sprite-loader')
  144. .loader('svg-sprite-loader')
  145. .end()
  146. config
  147. .when(process.env.ANALYZER == 'true', config => {
  148. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  149. config.plugin('webpack-bundle-analyzer').use(BundleAnalyzerPlugin).tap(() => [
  150. {
  151. analyzerPort: "auto"
  152. }
  153. ])
  154. })
  155. config
  156. .when(process.env.NODE_ENV !== 'development',
  157. config => {
  158. config
  159. .plugin('ScriptExtHtmlWebpackPlugin')
  160. .after('html')
  161. .use('script-ext-html-webpack-plugin', [{
  162. // `runtime` must same as runtimeChunk name. default is `runtime`
  163. inline: /runtime\..*\.js$/
  164. }])
  165. .end()
  166. config
  167. .optimization.splitChunks({
  168. chunks: 'all',
  169. cacheGroups: {
  170. libs: {
  171. name: 'libs',
  172. priority: 50,
  173. chunks: 'initial',
  174. },
  175. elementUI: {
  176. name: 'elementUI', // split elementUI into a single package
  177. priority: 40,
  178. test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
  179. },
  180. avue: {
  181. name: 'avue', // split avue into a single package
  182. priority: 40,
  183. test: /[\\/]node_modules[\\/]@smallwei(.*)/,
  184. reuseExistingChunk: true
  185. },
  186. echarts: {
  187. name: 'echarts',
  188. test: /[\\/]node_modules[\\/](?:vue-)?echarts/,
  189. priority: 40,
  190. },
  191. utils: {
  192. name: 'utils',
  193. test: /[\\/]src[\\/]utils|[\\/]node_modules[\\/](lodash|axios|crypto-js)/,
  194. priority: 30,
  195. },
  196. styles: {
  197. name: 'styles', // pack all remaining style files
  198. test: /\.(css|scss)$/,
  199. priority: 45,
  200. reuseExistingChunk: true
  201. },
  202. }
  203. })
  204. }
  205. )
  206. }
  207. }