vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 || 'vue Admin Template' // 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 methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  14. const Version = new Date().getTime()
  15. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  16. module.exports = {
  17. /**
  18. * You will need to set publicPath if you plan to deploy your site under a sub path,
  19. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  20. * then publicPath should be set to "/bar/".
  21. * In most cases please use '/' !!!
  22. * Detail: https://cli.vuejs.org/config/#publicpath
  23. */
  24. publicPath: '/',
  25. outputDir: 'dist',
  26. assetsDir: 'assets',
  27. // lintOnSave: process.env.NODE_ENV === 'development',
  28. lintOnSave: false,
  29. productionSourceMap: false,
  30. pages: {
  31. index: {
  32. entry: './src/main.js',
  33. template: './public/index.html',
  34. filename: 'index.html'
  35. }
  36. },
  37. devServer: {
  38. port: port,
  39. open: false,
  40. overlay: {
  41. warnings: false,
  42. errors: true
  43. },
  44. proxy: {
  45. // change xxx-api/login => mock/login
  46. // detail: https://cli.vuejs.org/config/#devserver-proxy
  47. [process.env.VUE_APP_BASE_API]: {
  48. // target: `http://127.0.0.1:${port}/mock`,
  49. // target: 'http://localhost:8888',
  50. target: 'https://localhost:8888',
  51. changeOrigin: true,
  52. pathRewrite: {
  53. ['^' + process.env.VUE_APP_BASE_API]: ''
  54. }
  55. }
  56. }
  57. },
  58. configureWebpack: {
  59. performance: {
  60. hints:'warning',
  61. //入口起点的最大体积 整数类型(以字节为单位)
  62. maxEntrypointSize: 50000000,
  63. //生成文件的最大体积 整数类型(以字节为单位 300k)
  64. maxAssetSize: 30000000,
  65. //只给出 js 文件的性能提示
  66. assetFilter: function(assetFilename) {
  67. return assetFilename.endsWith('.js');
  68. }
  69. },
  70. devtool: 'source-map',
  71. // provide the app's title in webpack's name field, so that
  72. // it can be accessed in index.html to inject the correct title.
  73. name: name,
  74. resolve: {
  75. alias: {
  76. '@': resolve('src')
  77. }
  78. },
  79. // output: { // 输出重构 打包编译后的 文件名称 【模块名称.版本号.时间戳】
  80. // // filename: utils.assetsPath('js/[name].[chunkhash].'+Version+'js'),
  81. // // chunkFilename: utils.assetsPath('js/[id].[chunkhash].'+Version+'js')
  82. // filename: 'static/js/[name].${Version}.js', // js打包文件,添加时间戳
  83. // chunkFilename: 'static/js/[name].${Version}.js'
  84. // }
  85. },
  86. chainWebpack(config) {
  87. config.plugins.delete('preload') // TODO: need test
  88. config.plugins.delete('prefetch') // TODO: need test
  89. // set svg-sprite-loader
  90. config.module
  91. .rule('svg')
  92. .exclude.add(resolve('src/icons'))
  93. .end()
  94. config.module
  95. .rule('icons')
  96. .test(/\.svg$/)
  97. .include.add(resolve('src/icons'))
  98. .end()
  99. .use('svg-sprite-loader')
  100. .loader('svg-sprite-loader')
  101. .options({
  102. symbolId: 'icon-[name]'
  103. })
  104. .end()
  105. // set preserveWhitespace
  106. config.module
  107. .rule('vue')
  108. .use('vue-loader')
  109. .loader('vue-loader')
  110. .tap(options => {
  111. options.compilerOptions.preserveWhitespace = true
  112. return options
  113. })
  114. .end()
  115. // img的文件名修改 // img打包文件,添加时间戳
  116. // config.module
  117. // .rule('images')
  118. // .use('url-loader')
  119. // .tap(options => {
  120. // options.name = `static/img/[name].${Version}.[ext]`
  121. // options.fallback = {
  122. // loader: 'file-loader',
  123. // options: {
  124. // name: `static/img/[name].${Version}.[ext]`
  125. // }
  126. // }
  127. // return options
  128. // })
  129. config
  130. // https://webpack.js.org/configuration/devtool/#development
  131. .when(process.env.NODE_ENV === 'development',
  132. config => config.devtool('cheap-source-map')
  133. )
  134. config
  135. .when(process.env.NODE_ENV !== 'development',
  136. config => {
  137. config
  138. .plugin('ScriptExtHtmlWebpackPlugin')
  139. .after('html')
  140. .use('script-ext-html-webpack-plugin', [{
  141. // `runtime` must same as runtimeChunk name. default is `runtime`
  142. inline: /runtime\..*\.js$/
  143. }])
  144. .end()
  145. /* config
  146. .optimization.splitChunks({
  147. chunks: 'all',
  148. cacheGroups: {
  149. libs: {
  150. name: 'chunk-libs',
  151. test: /[\\/]node_modules[\\/]/,
  152. priority: 10,
  153. chunks: 'initial' // only package third parties that are initially dependent
  154. },
  155. elementUI: {
  156. name: 'chunk-elementUI', // split elementUI into a single package
  157. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  158. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  159. },
  160. commons: {
  161. name: 'chunk-commons',
  162. test: resolve('src/main/frontend/components'), // can customize your rules
  163. minChunks: 3, // minimum common number
  164. priority: 5,
  165. reuseExistingChunk: true
  166. }
  167. }
  168. })
  169. config.optimization.runtimeChunk('single')*/
  170. }
  171. )
  172. }
  173. }