vue.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const CompressionPlugin = require('compression-webpack-plugin');
  2. module.exports = {
  3. publicPath: './',
  4. outputDir: './www',
  5. assetsDir: 'static',
  6. productionSourceMap: false,
  7. lintOnSave: true,
  8. filenameHashing: true,
  9. devServer: {
  10. https: false,
  11. port: 4562
  12. },
  13. configureWebpack: () => {
  14. if (process.env.NODE_ENV === 'production') {
  15. return {
  16. plugins: [
  17. new CompressionPlugin({
  18. minRatio: 1, // 压缩率小于1才会压缩
  19. test: /\.js$|.html$|\.css$/, // 匹配文件名
  20. threshold: 10240, // 对超过10k的文件进行压缩
  21. deleteOriginalAssets: false // 是否删除原文件
  22. })
  23. ],
  24. optimization: {
  25. runtimeChunk: 'single',
  26. splitChunks: {
  27. chunks: 'all',
  28. maxInitialRequests: Infinity,
  29. minSize: 20000,
  30. cacheGroups: {
  31. vendor: {
  32. test: /[\\/]node_modules[\\/]/,
  33. name(module) {
  34. // get the name. E.g. node_modules/packageName/not/this/part.js
  35. // or node_modules/packageName
  36. const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
  37. // npm package names are URL-safe, but some servers don't like @ symbols
  38. return `npm.${packageName.replace('@', '')}`
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }