Skip to content

Commit

Permalink
fix: set the default cacheGroups settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Repraance authored May 19, 2023
1 parent a52a4db commit 914e6f0
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/toolpack/src/webpack/config/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { withStyle } from './parts/style';
import { splitChunksFilter, commonChunkFilename } from './parts/helpers';

const BIG_LIBRARY_THRESHOLD = 160000; // byte
const SHUVI_PKGS_REGEX = /[\\/]node_modules[\\/]@shuvi[\\/]/;
const SHUVI_PKGS_REGEX = /[\\/]node_modules[\\/](@shuvi|doura)[\\/]/;
const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
const FRAMEWORK_REACT_MODULES: {
test: RegExp;
issuers?: RegExp[];
Expand Down Expand Up @@ -74,11 +75,37 @@ export function createBrowserWebpackChain(options: BaseOptions): WebpackChain {
if (dev) {
chain.plugin('private/hmr-plugin').use(webpack.HotModuleReplacementPlugin);
} else {
const getDefaultChunkName = (_module: any, chunks: any) => {
return crypto
.createHash('sha1')
.update(
chunks.reduce((acc: string, chunk: webpack.Chunk) => {
return acc + chunk.name;
}, '')
)
.digest('hex')
.substring(0, 8);
};

chain.optimization.splitChunks({
chunks: splitChunksFilter,
cacheGroups: {
default: false,
defaultVendors: false,
default: {
name: getDefaultChunkName,
filename: commonChunkFilename({ dev: false }),
idHint: '',
reuseExistingChunk: true,
minChunks: 2,
priority: -20
},
defaultVendors: {
name: getDefaultChunkName,
filename: commonChunkFilename({ dev: false }),
idHint: 'vendors',
reuseExistingChunk: true,
test: NODE_MODULES_REGEXP,
priority: -10
},
framework: {
chunks: 'all',
name: 'framework',
Expand Down Expand Up @@ -133,7 +160,7 @@ export function createBrowserWebpackChain(options: BaseOptions): WebpackChain {
}): boolean {
return (
module.size() > BIG_LIBRARY_THRESHOLD &&
/[/\\]node_modules[/\\]/.test(module.nameForCondition() || '')
NODE_MODULES_REGEXP.test(module.nameForCondition() || '')
);
},
name(module: {
Expand Down

0 comments on commit 914e6f0

Please sign in to comment.