vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const path = require('path')
  2. const CompressionPlugin = require("compression-webpack-plugin");
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
  8. lintOnSave: false,
  9. productionSourceMap: false,
  10. assetsDir: 'assets',
  11. // filenameHashing: false,
  12. // configureWebpack: () => {
  13. // if (process.env.NODE_ENV === 'production') {
  14. // return {
  15. // plugins: [
  16. // new CompressionPlugin({
  17. // test: /\.js$|\.html$|\.css$|\.jpg$|\.jpeg$|\.png/,
  18. // threshold: 10240,
  19. // deleteOriginalAssets: false
  20. // })
  21. // ]
  22. // }
  23. // }
  24. // },
  25. chainWebpack: config => {
  26. config.plugin('html')
  27. .tap(args => {
  28. args[0].title = '窍笔'
  29. // args[0].inlineSource = '(\.css|\.js$)'
  30. return args
  31. })
  32. // config.plugin('inline-source')
  33. // .use(require('html-webpack-inline-source-plugin'))
  34. config.plugins
  35. .delete('prefetch')
  36. .delete('preload')
  37. if (process.env.NODE_ENV === 'production') {
  38. // config.plugins.delete('html')
  39. }
  40. config.resolve.alias
  41. .set('@', path.join(__dirname, 'src'))
  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
  58. .when(process.env.NODE_ENV !== 'development',
  59. config => {
  60. config
  61. .plugin('ScriptExtHtmlWebpackPlugin')
  62. .after('html')
  63. .use('script-ext-html-webpack-plugin', [{
  64. // `runtime` must same as runtimeChunk name. default is `runtime`
  65. inline: /runtime\..*\.js$/
  66. }])
  67. .end()
  68. config
  69. .optimization.splitChunks({
  70. chunks: 'all',
  71. minSize: 20000, // 允许新拆出 chunk 的最小体积,也是异步 chunk 公共模块的强制拆分体积
  72. maxAsyncRequests: 6, // 每个异步加载模块最多能被拆分的数量
  73. maxInitialRequests: 6, // 每个入口和它的同步依赖最多能被拆分的数量
  74. enforceSizeThreshold: 50000, // 强制执行拆分的体积阈值并忽略其他限制
  75. cacheGroups: {
  76. vue: {
  77. name: 'vue',
  78. test: /[\\/]node_modules[\\/]_?vue(.*)/,
  79. priority: 10,
  80. },
  81. elementUI: {
  82. name: 'element-ui', // split elementUI into a single package
  83. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  84. priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
  85. },
  86. echarts: {
  87. name: 'echarts',
  88. test: /[\\/]node_modules[\\/]_?echarts(.*)/,
  89. priority: 30,
  90. },
  91. vendors: {
  92. name: 'vendors',
  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. devServer: {
  104. before:require('./mock/index.js'),
  105. port: 8087,
  106. overlay: {
  107. warnings: false,
  108. errors: false
  109. },
  110. proxy: {
  111. '/permission': {
  112. // target: 'http://192.168.2.122:8880',
  113. target: 'http://47.116.194.135:8085',
  114. ws: true,
  115. changeOrigin: true,
  116. pathRewrite:{
  117. '/api':''
  118. }
  119. },
  120. }
  121. }
  122. }