vue.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. const port = 9528 // dev port
  9. module.exports = {
  10. publicPath: '/',
  11. outputDir: 'dist',
  12. assetsDir: 'static',
  13. lintOnSave: process.env.NODE_ENV === 'development',
  14. productionSourceMap: false,
  15. devServer: {
  16. port: port,
  17. open: true,
  18. overlay: {
  19. warnings: false,
  20. errors: true
  21. },
  22. disableHostCheck: true, // webpack4.0 开启热更新
  23. proxy: {
  24. [process.env.VUE_APP_BASE_API]: {
  25. target: `http://127.0.0.1:${port}/mock`,
  26. changeOrigin: true,
  27. pathRewrite: {
  28. ['^' + process.env.VUE_APP_BASE_API]: ''
  29. }
  30. }
  31. }
  32. },
  33. configureWebpack: {
  34. name: name,
  35. resolve: {
  36. alias: {
  37. '@': resolve('src')
  38. }
  39. },
  40. performance: { // 性能设置
  41. hints: 'warning',
  42. maxEntrypointSize: 500000,
  43. maxAssetSize: 300000
  44. }
  45. },
  46. chainWebpack(config) {
  47. config.plugins.delete('preload') // TODO: need test
  48. config.plugins.delete('prefetch') // TODO: need test
  49. config.module
  50. .rule('svg')
  51. .exclude.add(resolve('src/icons'))
  52. .end()
  53. config.module
  54. .rule('icons')
  55. .test(/\.svg$/)
  56. .include.add(resolve('src/icons'))
  57. .end()
  58. .use('svg-sprite-loader')
  59. .loader('svg-sprite-loader')
  60. .options({
  61. symbolId: 'icon-[name]'
  62. })
  63. .end()
  64. config.module
  65. .rule('vue')
  66. .use('vue-loader')
  67. .loader('vue-loader')
  68. .tap(options => {
  69. options.compilerOptions.preserveWhitespace = true
  70. return options
  71. })
  72. .end()
  73. config
  74. .when(process.env.NODE_ENV === 'development',
  75. config => config.devtool('cheap-source-map')
  76. )
  77. config
  78. .when(process.env.NODE_ENV !== 'development',
  79. config => {
  80. config
  81. .plugin('ScriptExtHtmlWebpackPlugin')
  82. .after('html')
  83. .use('script-ext-html-webpack-plugin', [{
  84. inline: /runtime\..*\.js$/
  85. }])
  86. .end()
  87. config
  88. .optimization.splitChunks({
  89. chunks: 'all',
  90. cacheGroups: {
  91. libs: {
  92. name: 'chunk-libs',
  93. test: /[\\/]node_modules[\\/]/,
  94. priority: -10,
  95. chunks: 'initial' // only package third parties that are initially dependent
  96. }
  97. }
  98. })
  99. config.optimization.runtimeChunk('single')
  100. }
  101. )
  102. }
  103. }