vue.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const IS_PROD = ['production'].includes(process.env.NODE_ENV)
  2. const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i
  3. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  4. module.exports = {
  5. publicPath: '/',
  6. assetsDir: 'static',
  7. productionSourceMap: !IS_PROD,
  8. devServer: {
  9. port: 8081,
  10. overlay: {
  11. warning: false,
  12. errors: false
  13. },
  14. disableHostCheck: true,
  15. proxy: {
  16. '/api': {
  17. target: 'http://172.16.15.220:7002',
  18. changeOrigin: true,
  19. pathRewrite: {
  20. '^/api': '/'
  21. }
  22. }
  23. }
  24. },
  25. css: {
  26. loaderOptions: {
  27. sass: {
  28. data: `@import "~@/assets/style/variables.scss";`
  29. }
  30. }
  31. },
  32. configureWebpack: (config) => {
  33. const plugins = []
  34. if (IS_PROD) {
  35. plugins.push(
  36. new CompressionWebpackPlugin({
  37. filename: '[path].gz[query]',
  38. algorithm: 'gzip',
  39. test: productionGzipExtensions,
  40. threshold: 10240,
  41. minRatio: 0.8
  42. })
  43. )
  44. } else {
  45. // 开发阶段,便于浏览器调试
  46. config.devtool = 'source-map'
  47. }
  48. config.plugins = [...config.plugins, ...plugins]
  49. },
  50. chainWebpack: (config) => {
  51. config.resolve.symlinks(true)
  52. if (IS_PROD) {
  53. config.optimization.minimizer('terser').tap((args) => {
  54. args[0].terserOptions.compress.drop_console = true
  55. args[0].terserOptions.compress.drop_debugger = true
  56. args[0].terserOptions.compress.pure_funcs = ['console.log']
  57. args[0].terserOptions.output = {
  58. comments: false
  59. }
  60. return args
  61. })
  62. }
  63. }
  64. }