vue.config.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const path = require('path')
  2. function resolve(dir) {
  3. return path.join(__dirname, dir)
  4. }
  5. const name = '云票在线'
  6. module.exports = {
  7. publicPath: `/manage`,
  8. outputDir: 'dist',
  9. lintOnSave: true,
  10. productionSourceMap: false,
  11. css: {
  12. sourceMap: false,
  13. modules: false,
  14. loaderOptions: {
  15. stylus: {
  16. import: [resolve('./src/assets/css/index.styl')]
  17. }
  18. }
  19. },
  20. devServer: {
  21. port: 8002,
  22. open: true,
  23. proxy: {
  24. '/proxytemppath': {
  25. target: 'https://www.chtax.cn/api',
  26. // target: 'http://192.168.1.173:50009',
  27. secure: true, // 使用的是http协议则设置为false,https协议则设置为true
  28. changeOrigin: true,
  29. pathRewrite: {
  30. '^/proxytemppath': '/'
  31. }
  32. }
  33. }
  34. },
  35. configureWebpack: {
  36. name: name,
  37. resolve: {
  38. alias: {
  39. '@': resolve('src')
  40. }
  41. }
  42. },
  43. chainWebpack: config => {
  44. config.module
  45. .rule('svg')
  46. .exclude.add(resolve('src/assets/icons'))
  47. .end()
  48. config.module
  49. .rule('icons')
  50. .test(/\.svg$/)
  51. .include.add(resolve('src/assets/icons'))
  52. .end()
  53. .use('svg-sprite-loader')
  54. .loader('svg-sprite-loader')
  55. .options({
  56. symbolId: 'icon-[name]'
  57. })
  58. .end()
  59. config.when(process.env.NODE_ENV !== 'development',
  60. config => {
  61. config.optimization.splitChunks({
  62. chunks: 'all',
  63. cacheGroups: {
  64. libs: {
  65. name: 'chunk-libs',
  66. test: /[\\/]node_modules[\\/]/,
  67. priority: 10,
  68. chunks: 'initial' // 只打包初始时依赖的第三方
  69. },
  70. elementUI: {
  71. name: 'chunk-elementUI', // 单独将 elementUI 拆包
  72. priority: 20, // 权重要大于 libs 和 app 不然会被打包进 libs 或者 app
  73. test: /[\\/]node_modules[\\/]element-ui[\\/]/
  74. },
  75. commons: {
  76. name: 'chunk-commons',
  77. test: resolve('src/components'), // 可自定义拓展你的规则
  78. minChunks: 2, // 最小公用次数
  79. priority: 5,
  80. reuseExistingChunk: true
  81. }
  82. }
  83. })
  84. config.optimization.runtimeChunk('single')
  85. }
  86. )
  87. }
  88. }