| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const IS_PROD = ['production'].includes(process.env.NODE_ENV)
- const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i
- const CompressionWebpackPlugin = require('compression-webpack-plugin')
- module.exports = {
- publicPath: '/',
- assetsDir: 'static',
- productionSourceMap: !IS_PROD,
- devServer: {
- port: 8081,
- overlay: {
- warning: false,
- errors: false
- },
- disableHostCheck: true,
- proxy: {
- '/api': {
- target: 'http://172.16.15.220:7002',
- changeOrigin: true,
- pathRewrite: {
- '^/api': '/'
- }
- }
- }
- },
- css: {
- loaderOptions: {
- sass: {
- data: `@import "~@/assets/style/variables.scss";`
- }
- }
- },
- configureWebpack: (config) => {
- const plugins = []
- if (IS_PROD) {
- plugins.push(
- new CompressionWebpackPlugin({
- filename: '[path].gz[query]',
- algorithm: 'gzip',
- test: productionGzipExtensions,
- threshold: 10240,
- minRatio: 0.8
- })
- )
- } else {
- // 开发阶段,便于浏览器调试
- config.devtool = 'source-map'
- }
- config.plugins = [...config.plugins, ...plugins]
- },
- chainWebpack: (config) => {
- config.resolve.symlinks(true)
- if (IS_PROD) {
- config.optimization.minimizer('terser').tap((args) => {
- args[0].terserOptions.compress.drop_console = true
- args[0].terserOptions.compress.drop_debugger = true
- args[0].terserOptions.compress.pure_funcs = ['console.log']
- args[0].terserOptions.output = {
- comments: false
- }
- return args
- })
- }
- }
- }
|