Skip to content

Commit

Permalink
chore: current split
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 committed Dec 24, 2024
1 parent d0074b0 commit cd3287b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 82 deletions.
1 change: 0 additions & 1 deletion packages/modernjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"license": "MIT",
"dependencies": {
"@modern-js/node-bundle-require": "2.60.6",
"@module-federation/rsbuild-plugin": "workspace:*",
"@modern-js/utils": "2.60.6",
"@module-federation/enhanced": "workspace:*",
"@module-federation/node": "workspace:*",
Expand Down
30 changes: 28 additions & 2 deletions packages/modernjs/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { bundle } from '@modern-js/node-bundle-require';
import { PluginOptions } from '../types';
import { LOCALHOST, PLUGIN_IDENTIFIER } from '../constant';
import logger from './logger';
import { autoDeleteSplitChunkCacheGroups } from '@module-federation/rsbuild-plugin/utils';

import type { BundlerConfig, BundlerChainConfig } from '../interfaces/bundler';
import type {
Expand Down Expand Up @@ -302,7 +301,6 @@ export function patchBundlerConfig<T extends Bundler>(options: {
}

if (!isServer) {
// @ts-ignore
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
}

Expand Down Expand Up @@ -421,3 +419,31 @@ const SHARED_SPLIT_CHUNK_MAP = {
'@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
axios: SPLIT_CHUNK_MAP.AXIOS,
};

function autoDeleteSplitChunkCacheGroups<T extends Bundler>(
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions,
bundlerConfig: BundlerConfig<T>,
) {
if (!mfConfig.shared) {
return;
}
if (
!bundlerConfig.optimization?.splitChunks ||
!bundlerConfig.optimization.splitChunks.cacheGroups
) {
return;
}
const arrayShared = Array.isArray(mfConfig.shared)
? mfConfig.shared
: Object.keys(mfConfig.shared);
for (const shared of arrayShared) {
const splitChunkKey =
SHARED_SPLIT_CHUNK_MAP[shared as keyof typeof SHARED_SPLIT_CHUNK_MAP];
if (!splitChunkKey) {
continue;
}
if (bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey]) {
delete bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey];
}
}
}
Loading

0 comments on commit cd3287b

Please sign in to comment.