vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
  5. const MonacoLocalesPlugin = require('monaco-editor-locales-plugin');
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || 'vue Element Admin' // page title
  10. // If your port is set to 80,
  11. // use administrator privileges to execute the command line.
  12. // For example, Mac: sudo npm run
  13. // You can change the port by the following method:
  14. // port = 9527 npm run dev OR npm run dev --port = 9527
  15. const port = process.env.port || process.env.npm_config_port || 9090 // dev port
  16. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  17. module.exports = {
  18. /**
  19. * You will need to set publicPath if you plan to deploy your site under a sub path,
  20. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  21. * then publicPath should be set to "/bar/".
  22. * In most cases please use '/' !!!
  23. * Detail: https://cli.vuejs.org/config/#publicpath
  24. */
  25. publicPath: '/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. lintOnSave: false, // process..env.NODE_ENV === 'development',
  29. productionSourceMap: false,
  30. devServer: {
  31. port: port,
  32. open: true,
  33. overlay: {
  34. warnings: false,
  35. errors: true
  36. },
  37. proxy: {
  38. '/api': {
  39. // target: 'http://centerapi.admatch.cn/api',
  40. target: 'http://centerapi.admatch.cn/api',
  41. changeOrigin: true,
  42. pathRewrite: {
  43. '/api': ''
  44. }
  45. },
  46. '/mailapi': {
  47. target: 'http://emailtool.matchpages.com/mailapi',
  48. changeOrigin: true,
  49. pathRewrite: {
  50. '/mailapi': ''
  51. }
  52. }
  53. },
  54. before: require('./mock/mock-server.js')
  55. },
  56. configureWebpack: {
  57. // provide the app's title in webpack's name field, so that
  58. // it can be accessed in index.html to inject the correct title.
  59. devtool: 'eval-source-map',
  60. name: name,
  61. resolve: {
  62. alias: {
  63. '@': resolve('src')
  64. }
  65. },
  66. plugins: [
  67. new MonacoWebpackPlugin(),
  68. new MonacoLocalesPlugin({
  69. languages: ['zh-cn', 'en'],
  70. defaultLanguage: 'zh-cn'
  71. })
  72. ]
  73. },
  74. chainWebpack(config) {
  75. // it can improve the speed of the first screen, it is recommended to turn on preload
  76. // it can improve the speed of the first screen, it is recommended to turn on preload
  77. config.plugin('preload').tap(() => [
  78. {
  79. rel: 'preload',
  80. // to ignore runtime.js
  81. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  82. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  83. include: 'initial'
  84. }
  85. ])
  86. // when there are many pages, it will cause too many meaningless requests
  87. config.plugins.delete('prefetch')
  88. // set svg-sprite-loader
  89. config.module
  90. .rule('svg')
  91. .exclude.add(resolve('src/icons'))
  92. .end()
  93. config.module
  94. .rule('icons')
  95. .test(/\.svg$/)
  96. .include.add(resolve('src/icons'))
  97. .end()
  98. .use('svg-sprite-loader')
  99. .loader('svg-sprite-loader')
  100. .options({
  101. symbolId: 'icon-[name]'
  102. })
  103. .end()
  104. config
  105. .when(process.env.NODE_ENV !== 'development',
  106. config => {
  107. config
  108. .plugin('ScriptExtHtmlWebpackPlugin')
  109. .after('html')
  110. .use('script-ext-html-webpack-plugin', [{
  111. // `runtime` must same as runtimeChunk name. default is `runtime`
  112. inline: /runtime\..*\.js$/
  113. }])
  114. .end()
  115. config
  116. .optimization.splitChunks({
  117. chunks: 'all',
  118. cacheGroups: {
  119. libs: {
  120. name: 'chunk-libs',
  121. test: /[\\/]node_modules[\\/]/,
  122. priority: 10,
  123. chunks: 'initial' // only package third parties that are initially dependent
  124. },
  125. elementUI: {
  126. name: 'chunk-elementUI', // split elementUI into a single package
  127. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  128. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  129. },
  130. commons: {
  131. name: 'chunk-commons',
  132. test: resolve('src/components'), // can customize your rules
  133. minChunks: 3, // minimum common number
  134. priority: 5,
  135. reuseExistingChunk: true
  136. }
  137. }
  138. })
  139. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  140. config.optimization.runtimeChunk('single')
  141. config.devtool('eval-source-map')
  142. }
  143. )
  144. }
  145. }