vue.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-16 11:27:35
  4. * @LastEditTime: 2021-09-28 11:02:09
  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. }
  42. },
  43. css: {
  44. loaderOptions: {
  45. less: {
  46. javascriptEnabled: true,
  47. }
  48. }
  49. },
  50. };