vue.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  2. const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
  3. module.exports = {
  4. publicPath: './', // 相对于 HTML 页面(目录相同)
  5. // 添加web worker loader
  6. // configureWebpack: config => {
  7. // config.module.rules.push({
  8. // test: /\.worker\.js$/,
  9. // use: {
  10. // loader: 'worker-loader',
  11. // options: { inline: true }
  12. // }
  13. // })
  14. // },
  15. // devServer: {
  16. // proxy: {
  17. // '/api': {
  18. // target: 'http://192.168.1.53:10080/',
  19. // changeOrigin: true,
  20. // }
  21. // }
  22. // }
  23. configureWebpack: config => {
  24. if(process.env.NODE_ENV === 'production') {
  25. config.plugins.push(
  26. new CompressionWebpackPlugin({
  27. /* [file]被替换为原始资产文件名。
  28. [path]替换为原始资产的路径。
  29. [dir]替换为原始资产的目录。
  30. [name]被替换为原始资产的文件名。
  31. [ext]替换为原始资产的扩展名。
  32. [query]被查询替换。*/
  33. filename: '[path].gz[query]',
  34. //压缩算法
  35. algorithm: 'gzip',
  36. //匹配文件
  37. test: productionGzipExtensions,
  38. //压缩超过此大小的文件,以字节为单位
  39. threshold: 10240,
  40. minRatio: 0.8,
  41. //删除原始文件只保留压缩后的文件
  42. //deleteOriginalAssets: false
  43. })
  44. )
  45. }
  46. },
  47. };