vue.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-16 11:27:35
  4. * @LastEditTime: 2021-11-29 15:29:40
  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. const webpack = require('webpack')
  13. module.exports = {
  14. publicPath: './', // 相对于 HTML 页面(目录相同)
  15. chainWebpack: config => {
  16. config.plugin('provide').use(webpack.ProvidePlugin, [{
  17. $: 'jquery',
  18. jquery: 'jquery',
  19. jQuery: 'jquery',
  20. 'window.jQuery': 'jquery'
  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. config.resolve.alias = {
  47. '@': path.resolve(__dirname, 'src'),
  48. 'components': '@/components',
  49. 'views': '@/views',
  50. 'assets': '@/assets',
  51. 'utils': '@/utils'
  52. }
  53. },
  54. css: {
  55. loaderOptions: {
  56. less: {
  57. javascriptEnabled: true,
  58. }
  59. }
  60. },
  61. lintOnSave: false,
  62. };