const CompressionPlugin = require("compression-webpack-plugin")
// 代码压缩
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'
)
module.exports = {
publicPath: './', //部署应用时的根路径(默认'/'),也可用相对路径(存在使用限制)
outputDir: 'dist', //运行时生成的生产环境构建文件的目录(默认'dist',构建之前会被清除)
assetsDir: '', //静态资源目录(js、css、img、fonts),相对outputDir的目录(默认'')
indexPath: 'index.html', //指定生成index.html的输出路径(相对outputDir)也可以是绝对路径
lintOnSave: true, //是否开启ESlint(保存时检查)
productionSourceMap: false, //生产环境是否生成 sourceMap 文件
}
return {
plugins: [
new CompressionPlugin({
test: /\.js$|\.html$|.\css/, //匹配文件名
threshold: 10240, //对超过10k的数据压缩
deleteOriginalAssets: false, //不删除源文件
minRatio: 0.8,
algorithm:'gzip'
}),
new UglifyJsPlugin({
uglifyOptions: {
output:{
comments:false, //去掉注释
},
warnings: false, //去除警告
//生产环境自动删除console
compress: {
drop_debugger: true,
drop_console: true,
pure_funcs: ['console.log']
},
},
cache: false,
sourceMap: false,
parallel: true
})
],
performance:{
maxEntrypointSize: 50000000,// 入口起点的最大体积
maxAssetSize: 30000000,// 生成文件的最大体积
assetFilter: function(assetFilename) {
return assetFilename.endsWith('.js');
}
}
}
chainWebpack: config => {
//最小化代码
config.optimization.minimize(true);
//分割代码
config.optimization.splitChunks({
chunks: 'all'
});
config.plugins.delete("prefetch") //移除首次加载多余请求
config.plugins.delete('preload'); // 移除 preload 插件
//压缩图片
config.module
.rule('images')
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({
bypassOnDebug: true
})
.end()
},
css: {
extract: true, //是否使用css分离插件 ExtractTextPlugin
sourceMap: false, //开启 CSS source maps
loaderOptions: {}, //css预设器配置项
requireModuleExtension: true //启用CSS modules for all css / pre-processor files.
},
devServer: { //环境配置
host: 'xx.xx.xx.xx', // 自己的ip
port: 22222,
https: false, //是否开启https
hotOnly: false, //是否配置热更新
open: true, //配置自动启动浏览器
proxy: { //配置多个代理跨域(配置一个 proxy: 'http://localhost:4000' )
'/': {
target: 'http://xx.xx.xx.xx:9000', //测试服务
// target: 'https://szlsy.softetone.com',
ws: true,//是否websocket
changeOrigin: true, //是否跨域
pathRewrite: {
'^/': ''
}
},
}
},
pluginOptions: { // 第三方插件配置
// ...
}
大概就这么多吧,上证据。
行不行试试就知道了,留个赞呗!