vue.config.js 2.9 KB

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