Skip to content

Commit

Permalink
feat: support split-by-module with rspack (#5057)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 18, 2023
1 parent acd3861 commit 9877fd5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import type { PerformanceConfig } from '../../types';

const BaseChunkSplitSchema: z.ZodType<BaseChunkSplit> =
BaseSplitRulesSchema.extend({
strategy: z.enum(['split-by-experience', 'all-in-one', 'single-vendor']),
strategy: z.enum([
'split-by-module',
'split-by-experience',
'all-in-one',
'single-vendor',
]),
forceSplitting: ForceSplittingSchema,
override: z.any().optional(),
});
Expand Down
6 changes: 4 additions & 2 deletions packages/builder/builder-shared/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export async function isFileExists(file: string) {
.catch(() => false);
}

export function getPackageNameFromModulePath(modulePath: string) {
export function getPackageNameFromModulePath(
modulePath: string,
): string | undefined {
const handleModuleContext = modulePath?.match(MODULE_PATH_REGEX);

if (!handleModuleContext) {
return false;
return undefined;
}

const [, , scope, name] = handleModuleContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export interface BaseSplitRules {
}

export interface BaseChunkSplit extends BaseSplitRules {
/** todo: split-by-module not support in Rspack */
strategy:
| 'split-by-module'
| 'split-by-experience'
Expand Down
3 changes: 1 addition & 2 deletions packages/builder/builder/src/plugins/splitChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ function splitByModule(ctx: SplitChunksContext): SplitChunks {
vendors: {
priority: -10,
test: NODE_MODULES_REGEX,
// todo: not support in rspack
name(module: { context: string | null }): string | false {
name(module: { context: string | null }): string | undefined {
return getPackageNameFromModulePath(module.context!);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ Builder 默认采用 `split-by-experience` 策略,这是我们根据经验制

如果你想使用其他拆包策略,可以通过 `performance.chunkSplit.strategy` 配置项来指定。

:::tip
在使用 Rspack 作为打包工具时,暂时不支持采用 `split-by-module` 策略。
:::

### chunkSplit.minSize

- **类型:** `number`
Expand Down

0 comments on commit 9877fd5

Please sign in to comment.