| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- const path = require('path')
- const resolve = (dir) => path.join(__dirname, dir)
- 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',
- lintOnSave: false, //关闭eslint校验
- productionSourceMap: !IS_PROD,
- devServer: {
- port: 8081,
- overlay: {
- warning: false,
- errors: false
- },
- disableHostCheck: true,
- proxy: {
- '/admin': {
- target: process.env.VUE_APP_API_URL,
- changeOrigin: true,
- pathRewrite: {
- '^/admin': '/admin',
- }
- },
- }
- },
- 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
- })
- }
- }
- }
|