From 6b03be8bdf094bc693066016cd11a9f872586878 Mon Sep 17 00:00:00 2001 From: gaoyuan Date: Fri, 15 Sep 2023 11:30:28 +0800 Subject: [PATCH] feat(builder): apply chunkIds deterministic in Rspack mode production (#4654) --- .changeset/stale-comics-change.md | 7 +++++++ .../builder-rspack-provider/src/plugins/transition.ts | 8 +++++++- .../tests/plugins/__snapshots__/default.test.ts.snap | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/stale-comics-change.md diff --git a/.changeset/stale-comics-change.md b/.changeset/stale-comics-change.md new file mode 100644 index 000000000000..3a3599378448 --- /dev/null +++ b/.changeset/stale-comics-change.md @@ -0,0 +1,7 @@ +--- +'@modern-js/builder-rspack-provider': patch +--- + +chore(builder): apply chunkIds deterministic in Rspack mode production + +chore(builder): 在 Rspack 模式下,生产环境开启 chunkIds 'deterministic' diff --git a/packages/builder/builder-rspack-provider/src/plugins/transition.ts b/packages/builder/builder-rspack-provider/src/plugins/transition.ts index 163e0c1d64dd..80518605cc57 100644 --- a/packages/builder/builder-rspack-provider/src/plugins/transition.ts +++ b/packages/builder/builder-rspack-provider/src/plugins/transition.ts @@ -6,7 +6,13 @@ import type { BuilderPlugin } from '../types'; export const builderPluginTransition = (): BuilderPlugin => ({ name: 'builder-plugin-transition', - setup() { + setup(api) { process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent'; + + api.modifyBundlerChain(async (chain, { isProd }) => { + if (isProd) { + chain.optimization.chunkIds('deterministic'); + } + }); }, }); diff --git a/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap b/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap index 65b1bb0e0d6a..9638b0e2a21b 100644 --- a/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap +++ b/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap @@ -1390,6 +1390,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "name": "Client", "optimization": { + "chunkIds": "deterministic", "minimize": true, "minimizer": [ Plugin {