vue.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const path = require('path')
  2. const defaultSettings = require('./src/settings.js')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. publicPath: './',
  8. outputDir: 'dist',
  9. assetsDir: 'static',
  10. lintOnSave: process.env.NODE_ENV === 'development',
  11. productionSourceMap: false,
  12. devServer: {
  13. port: 9527,
  14. open: true,
  15. overlay: {
  16. warnings: false,
  17. errors: true
  18. },
  19. proxy: {
  20. [process.env.VUE_APP_BASE_API]: {
  21. target: 'https://admin.jiuweiyun.cn/api',
  22. // target: 'http://192.168.0.6:8199/api',
  23. // target: 'http://192.168.0.15:8016/api',
  24. changeOrigin: true,
  25. pathRewrite: {
  26. ['^' + process.env.VUE_APP_BASE_API]: ''
  27. }
  28. }
  29. }
  30. },
  31. configureWebpack: {
  32. name: defaultSettings.title,
  33. resolve: {
  34. alias: {
  35. '@': resolve('src')
  36. }
  37. }
  38. },
  39. chainWebpack(config) {
  40. config.plugins.delete('preload')
  41. config.plugins.delete('prefetch')
  42. config.module
  43. .rule('svg')
  44. .exclude.add(resolve('src/icons'))
  45. .end()
  46. config.module
  47. .rule('icons')
  48. .test(/\.svg$/)
  49. .include.add(resolve('src/icons'))
  50. .end()
  51. .use('svg-sprite-loader')
  52. .loader('svg-sprite-loader')
  53. .options({
  54. symbolId: 'icon-[name]'
  55. })
  56. .end()
  57. config.module
  58. .rule('vue')
  59. .use('vue-loader')
  60. .loader('vue-loader')
  61. .tap(options => {
  62. options.compilerOptions.preserveWhitespace = true
  63. return options
  64. })
  65. .end()
  66. config
  67. .when(process.env.NODE_ENV === 'development',
  68. config => config.devtool('cheap-source-map')
  69. )
  70. config
  71. .when(process.env.NODE_ENV !== 'development',
  72. config => {
  73. config
  74. .plugin('ScriptExtHtmlWebpackPlugin')
  75. .after('html')
  76. .use('script-ext-html-webpack-plugin', [{
  77. // `runtime` must same as runtimeChunk name. default is `runtime`
  78. inline: /runtime\..*\.js$/
  79. }])
  80. .end()
  81. config
  82. .optimization.splitChunks({
  83. chunks: 'all',
  84. cacheGroups: {
  85. libs: {
  86. name: 'chunk-libs',
  87. test: /[\\/]node_modules[\\/]/,
  88. priority: 10,
  89. chunks: 'initial' // only package third parties that are initially dependent
  90. },
  91. elementUI: {
  92. name: 'chunk-elementUI', // split elementUI into a single package
  93. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  94. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  95. },
  96. commons: {
  97. name: 'chunk-commons',
  98. test: resolve('src/components'), // can customize your rules
  99. minChunks: 3, // minimum common number
  100. priority: 5,
  101. reuseExistingChunk: true
  102. }
  103. }
  104. })
  105. config.optimization.runtimeChunk('single')
  106. }
  107. )
  108. }
  109. }