vue.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-16 11:27:35
  4. * @LastEditTime: 2021-10-11 10:17:10
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \hyyfClient\vue.config.js
  8. */
  9. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  10. const path = require('path')
  11. const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
  12. module.exports = {
  13. publicPath: './', // 相对于 HTML 页面(目录相同)
  14. configureWebpack: config => {
  15. if(process.env.NODE_ENV === 'production') {
  16. config.plugins.push(
  17. new CompressionWebpackPlugin({
  18. /* [file]被替换为原始资产文件名。
  19. [path]替换为原始资产的路径。
  20. [dir]替换为原始资产的目录。
  21. [name]被替换为原始资产的文件名。
  22. [ext]替换为原始资产的扩展名。
  23. [query]被查询替换。*/
  24. filename: '[path].gz[query]',
  25. //压缩算法
  26. algorithm: 'gzip',
  27. //匹配文件
  28. test: productionGzipExtensions,
  29. //压缩超过此大小的文件,以字节为单位
  30. threshold: 10240,
  31. minRatio: 0.8,
  32. //删除原始文件只保留压缩后的文件
  33. //deleteOriginalAssets: false
  34. })
  35. )
  36. }
  37. config.resolve.alias = {
  38. '@': path.resolve(__dirname, 'src'),
  39. 'components': '@/components',
  40. 'views': '@/views',
  41. 'assets': '@/assets'
  42. }
  43. },
  44. css: {
  45. loaderOptions: {
  46. less: {
  47. javascriptEnabled: true,
  48. }
  49. }
  50. },
  51. };