vue.config.js 1.7 KB

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