You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

63 lines
1.7 KiB

  1. /**
  2. * 配置参考:
  3. * https://cli.vuejs.org/zh/config/
  4. */
  5. const url = process.env.VUE_APP_BASE_API // 配置.env文件通过运行命令启动不同调试环境
  6. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  7. const productionGzipExtensions = ['js', 'css']
  8. module.exports = {
  9. lintOnSave: true,
  10. productionSourceMap: false,
  11. chainWebpack: config => {
  12. const entry = config.entry('app')
  13. entry
  14. .add('babel-polyfill')
  15. .end()
  16. entry
  17. .add('classlist-polyfill')
  18. .end()
  19. },
  20. css: {
  21. // 忽略 CSS order 顺序警告
  22. extract: { ignoreOrder: true }
  23. },
  24. configureWebpack: (config) => {
  25. if (process.env.NODE_ENV === 'production') {
  26. // 仅在生产环境下启用该配置
  27. return {
  28. performance: {
  29. // 打包后最大文件大小限制
  30. maxAssetSize: 1024000
  31. },
  32. plugins: [
  33. new CompressionWebpackPlugin({
  34. // filename: '[path].gz[query]',
  35. // algorithm: 'gzip',
  36. // test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  37. // threshold: 1024, // 只有大小大于该值的资源会被处理,当前配置为对于超过1k的数据进行处理,不足1k的可能会越压缩越大
  38. // minRatio: 0.99, // 只有压缩率小于这个值的资源才会被处理
  39. // deleteOriginalAssets: true // 删除原文件
  40. })
  41. ]
  42. }
  43. }
  44. },
  45. // 配置转发代理
  46. devServer: {
  47. disableHostCheck: true,
  48. port: 8080,
  49. proxy: {
  50. '/': {
  51. target: url,
  52. ws: false, // 需要websocket 开启
  53. pathRewrite: {
  54. '^/': '/'
  55. }
  56. },
  57. // 3.5 以后不需要再配置
  58. }
  59. }
  60. }