vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const path = require('path')
  2. function resolve(dir) {
  3. return path.join(__dirname, dir)
  4. }
  5. module.exports = {
  6. publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
  7. lintOnSave: false,
  8. productionSourceMap: false,
  9. assetsDir: 'assets',
  10. chainWebpack: config => {
  11. config.plugin('html')
  12. .tap(args => {
  13. args[0].title = '文件差异对比系统'
  14. return args
  15. })
  16. // config.plugin('inline-source')
  17. // .use(require('html-webpack-inline-source-plugin'))
  18. config.plugins
  19. .delete('prefetch')
  20. .delete('preload')
  21. if (process.env.NODE_ENV === 'production') {
  22. // config.plugins.delete('html')
  23. }
  24. config.resolve.alias
  25. .set('@', path.join(__dirname, 'src'))
  26. config.module
  27. .rule('svg')
  28. .exclude.add(resolve('src/icons'))
  29. .end()
  30. config.module
  31. .rule('icons')
  32. .test(/\.svg$/)
  33. .include.add(resolve('src/icons'))
  34. .end()
  35. .use('svg-sprite-loader')
  36. .loader('svg-sprite-loader')
  37. .options({
  38. symbolId: 'icon-[name]'
  39. })
  40. .end()
  41. config
  42. .when(process.env.NODE_ENV !== 'development',
  43. config => {
  44. config
  45. .plugin('ScriptExtHtmlWebpackPlugin')
  46. .after('html')
  47. .use('script-ext-html-webpack-plugin', [{
  48. // `runtime` must same as runtimeChunk name. default is `runtime`
  49. inline: /runtime\..*\.js$/
  50. }])
  51. .end()
  52. config
  53. .optimization.splitChunks({
  54. chunks: 'all',
  55. minSize: 20000, // 允许新拆出 chunk 的最小体积,也是异步 chunk 公共模块的强制拆分体积
  56. maxAsyncRequests: 6, // 每个异步加载模块最多能被拆分的数量
  57. maxInitialRequests: 6, // 每个入口和它的同步依赖最多能被拆分的数量
  58. enforceSizeThreshold: 50000, // 强制执行拆分的体积阈值并忽略其他限制
  59. cacheGroups: {
  60. vue: {
  61. name: 'vue',
  62. test: /[\\/]node_modules[\\/]_?vue(.*)/,
  63. priority: 10,
  64. },
  65. elementUI: {
  66. name: 'element-ui', // split elementUI into a single package
  67. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  68. priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
  69. },
  70. echarts: {
  71. name: 'echarts',
  72. test: /[\\/]node_modules[\\/]_?echarts(.*)/,
  73. priority: 30,
  74. },
  75. vendors: {
  76. name: 'vendors',
  77. test: /[\\/]node_modules[\\/]/,
  78. priority: -10,
  79. chunks: 'initial' // only package third parties that are initially dependent
  80. },
  81. }
  82. })
  83. config.optimization.runtimeChunk('single')
  84. }
  85. )
  86. },
  87. devServer: {
  88. port: 8089,
  89. // overlay: {
  90. // warnings: false,
  91. // errors: false
  92. // },
  93. proxy: {
  94. '/permission': {
  95. // target: 'http://192.168.0.57:8879',
  96. target: 'http://192.168.1.24:8871',
  97. ws: true,
  98. changeOrigin: true,
  99. pathRewrite:{
  100. '/api':''
  101. }
  102. },
  103. }
  104. }
  105. }