build: 优化打包体积 (#1323)

* 移除生产环境不必要的 map 文件
* webpack 添加 LimitChunkCountPlugin 用以解决 chunk 包太多的问题
This commit is contained in:
Chuwen 2022-02-23 23:26:37 +08:00 committed by GitHub
parent 91b4e08449
commit 76b358445e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,12 @@
const webpack = require('webpack');
const path = require('path'); const path = require('path');
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, dir); return path.join(__dirname, dir);
} }
module.exports = { module.exports = {
// 生产环境打包不输出 map
productionSourceMap: false,
devServer: { devServer: {
disableHostCheck: true, disableHostCheck: true,
port: process.env.DEV_SERVER_PORT || 8080, port: process.env.DEV_SERVER_PORT || 8080,
@ -53,6 +56,13 @@ module.exports = {
symbolId: 'icon-[name]', symbolId: 'icon-[name]',
}) })
.end(); .end();
// LimitChunkCountPlugin 可以通过合并块来对块进行后期处理。用以解决 chunk 包太多的问题
config.plugin('chunkPlugin').use(webpack.optimize.LimitChunkCountPlugin, [
{
maxChunks: 3,
minChunkSize: 10_000,
},
]);
}, },
// 添加插件的配置 // 添加插件的配置
pluginOptions: { pluginOptions: {