Commit 3a1b61e8 authored by 武广's avatar 武广

fix: 优化打包 - 多进程打包 + sourcemap

parent a3f611a8
......@@ -62,8 +62,11 @@ export default {
targets: {
ie: 11,
},
// devtool: process.env.SENTRY_ENV === 'test' ? false : 'hidden-source-map',
devtool: false,
devtool: 'hidden-source-map',
// devtool: '#source-map',
// uglifyJSOptions: {
// sourceMap: true
// },
// umi routes: https://umijs.org/zh/guide/router.html
routes: [
{
......@@ -341,7 +344,11 @@ export default {
},
},
},
chunks: ['umi', 'antdesigns'],
chainWebpack: webpackPlugin,
nodeModulesTransform: {
type: 'none',
},
/*
proxy: {
'/server/api/': {
......
......@@ -5,6 +5,8 @@
import ThemeColorReplacer from 'webpack-theme-color-replacer';
import generate from '@ant-design/colors/lib/generate';
import path from 'path';
const HappyPack = require('happypack');
const happyThreadPool = HappyPack.ThreadPool({ size: require('os').cpus().length });
const SentryPlugin = require('@qg/sentry-webpack-plugin');
const SentryConfig = require('../.sentryclirc');
function getModulePackageName(module) {
......@@ -31,6 +33,13 @@ export default config => {
if (process.env.NODE_ENV === 'production') {
config.plugin('sentry-webpack-plugin').use(SentryPlugin, [SentryConfig]);
}
config.plugin('HappyPack').use(HappyPack, [
{
id: 'js',
loaders: ['babel-loader'],
threadPool: happyThreadPool,
},
]);
// preview.pro.ant.design only do not use in your production;
if (
process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ||
......@@ -63,13 +72,26 @@ export default config => {
} // optimize chunks
config.optimization // share the same chunks across different modules
.runtimeChunk(false)
// .runtimeChunk(false)
.splitChunks({
chunks: 'async',
name: 'vendors',
maxInitialRequests: Infinity,
minSize: 0,
// maxInitialRequests: Infinity,
name: true, // chunk 的名称,如果设置为固定的字符串那么所有的 chunk 都会被合并成一个,这就是为什么 umi 默认只有一个 vendors.async.js。
minSize: 30000, // byte, == 30 kb,越大那么单个文件越大,chunk 数就会变少(针对于提取公共 chunk 的时候,不管再大也不会把动态加载的模块合并到初始化模块中)当这个值很大的时候就不会做公共部分的抽取了
maxSize: 0, // 文件的最大尺寸,优先级:maxInitialRequest/maxAsyncRequests < maxSize < minSize,需要注意的是这个如果配置了,umi.js 就可能被拆开,最后构建出来的 chunkMap 中可能就找不到 umi.js 了。
minChunks: 3, // 被提取的一个模块至少需要在几个 chunk 中被引用,这个值越大,抽取出来的文件就越小
maxAsyncRequests: 10, // 在做一次按需加载的时候最多有多少个异步请求,为 1 的时候就不会抽取公共 chunk 了
maxInitialRequests: Infinity, //5, // 针对一个 entry 做初始化模块分隔的时候的最大文件数,优先级高于 cacheGroup,所以为 1 的时候就不会抽取 initial common 了。
automaticNameDelimiter: '.',
cacheGroups: {
antdesigns: {
// antdsign
name: 'antdesigns',
chunks: 'all',
test: /(@antd|antd|@ant-design)/,
priority: 10,
enforce: true,
},
vendors: {
test: module => {
const packageName = getModulePackageName(module) || '';
......@@ -99,6 +121,8 @@ export default config => {
return 'misc';
},
priority: -11,
enforce: true,
},
},
});
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment