vue.config.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const { WebUpdateNotificationPlugin } = require('@plugin-web-update-notification/webpack')
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. const name = defaultSettings.title || 'Member Management System' // page title
  9. // If your port is set to 80,
  10. // use administrator privileges to execute the command line.
  11. // For example, Mac: sudo npm run
  12. // You can change the port by the following method:
  13. // port = 9527 npm run dev OR npm run dev --port = 9527
  14. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  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: process.env.NODE_ENV === 'production' ? './' : '/',
  25. outputDir: 'dist',
  26. assetsDir: 'static',
  27. lintOnSave: process.env.NODE_ENV === 'development',
  28. productionSourceMap: false,
  29. devServer: {
  30. port: port,
  31. open: true,
  32. overlay: {
  33. warnings: false,
  34. errors: true
  35. },
  36. proxy: {
  37. [process.env.VUE_APP_BASE_API]: {
  38. target: 'http://16.163.228.151:8043',
  39. changeOrigin: true,
  40. pathRewrite: {
  41. [ '^' + process.env.VUE_APP_BASE_API ]: ''
  42. }
  43. }
  44. }
  45. /* before: require('./mock/mock-server.js') */
  46. },
  47. configureWebpack: {
  48. // provide the app's title in webpack's name field, so that
  49. // it can be accessed in index.html to inject the correct title.
  50. name: name,
  51. resolve: {
  52. alias: {
  53. '@': resolve('src')
  54. }
  55. },
  56. plugins: [
  57. new WebUpdateNotificationPlugin({
  58. logVersion: true,
  59. // plugin preset: zh_CN | zh_TW | en_US
  60. locale: 'en_US',
  61. localeData: {
  62. en_US: {
  63. title: '📢 system update',
  64. description: 'System update, please refresh the page',
  65. buttonText: 'refresh',
  66. dismissButtonText: 'dismiss'
  67. },
  68. zh_CN: {
  69. title: '📢 系统更新',
  70. description: '系统更新,请刷新页面',
  71. buttonText: '刷新',
  72. dismissButtonText: '取消'
  73. }
  74. }
  75. })
  76. ]
  77. },
  78. chainWebpack(config) {
  79. // it can improve the speed of the first screen, it is recommended to turn on preload
  80. // it can improve the speed of the first screen, it is recommended to turn on preload
  81. config.plugin('preload').tap(() => [
  82. {
  83. rel: 'preload',
  84. // to ignore runtime.js
  85. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  86. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  87. include: 'initial'
  88. }
  89. ])
  90. // when there are many pages, it will cause too many meaningless requests
  91. config.plugins.delete('prefetch')
  92. // set svg-sprite-loader
  93. config.module
  94. .rule('svg')
  95. .exclude.add(resolve('src/icons'))
  96. .end()
  97. config.module
  98. .rule('icons')
  99. .test(/\.svg$/)
  100. .include.add(resolve('src/icons'))
  101. .end()
  102. .use('svg-sprite-loader')
  103. .loader('svg-sprite-loader')
  104. .options({
  105. symbolId: 'icon-[name]'
  106. })
  107. .end()
  108. config
  109. .when(process.env.NODE_ENV !== 'development',
  110. config => {
  111. config
  112. .plugin('ScriptExtHtmlWebpackPlugin')
  113. .after('html')
  114. .use('script-ext-html-webpack-plugin', [{
  115. // `runtime` must same as runtimeChunk name. default is `runtime`
  116. inline: /runtime\..*\.js$/
  117. }])
  118. .end()
  119. config
  120. .optimization.splitChunks({
  121. chunks: 'all',
  122. cacheGroups: {
  123. libs: {
  124. name: 'chunk-libs',
  125. test: /[\\/]node_modules[\\/]/,
  126. priority: 10,
  127. chunks: 'initial' // only package third parties that are initially dependent
  128. },
  129. elementUI: {
  130. name: 'chunk-elementUI', // split elementUI into a single package
  131. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  132. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  133. },
  134. commons: {
  135. name: 'chunk-commons',
  136. test: resolve('src/components'), // can customize your rules
  137. minChunks: 3, // minimum common number
  138. priority: 5,
  139. reuseExistingChunk: true
  140. }
  141. }
  142. })
  143. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  144. config.optimization.runtimeChunk('single')
  145. }
  146. )
  147. }
  148. }
  149. // other file to set locale
  150. window.pluginWebUpdateNotice_.setLocale('en_US');