const CompressionWebpackPlugin = require('compression-webpack-plugin') const path = require('path') const CopyWebpackPlugin = require('copy-webpack-plugin') module.exports = { // eslint-loader 是否在保存的时候检查 lintOnSave: true, // webpack配置 configureWebpack: config => { if (process.env.UNI_PLATFORM === 'h5') { // 开启gzip压缩 config.plugins = [ ...config.plugins, new CompressionWebpackPlugin({ filename: '[path].gz[query]', algorithm: 'gzip', test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'), threshold: 8192, minRatio: 0.8, }), ] // public目录下文件文件设置为静态资源目录 config.plugins = [ ...config.plugins, new CopyWebpackPlugin([ { from: path.join(__dirname, 'public'), to: path.join(__dirname, 'dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM), }, ]), ] } }, // 生产环境是否生成 sourceMap 文件 productionSourceMap: false, // css相关配置 css: { sourceMap: process.env.NODE_ENV !== 'production', loaderOptions: { scss: { prependData: `@import "~@/common/scss/public.scss";`, }, }, }, // webpack-dev-server 相关配置 devServer: { open: false, // 配置自动启动浏览器 port: 8080, // 端口号 https: false, hotOnly: true, disableHostCheck: true, proxy: '',// 设置代理 }, // 第三方插件配置 pluginOptions: {}, }