Skip to content

Commit 98136ca

Browse files
authored
fix(modern-js-plugin): use contenthash instead of chunkhash (#3855)
1 parent 790302a commit 98136ca

File tree

10 files changed

+21
-9
lines changed

10 files changed

+21
-9
lines changed

.changeset/ninety-points-impress.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/nextjs-mf': patch
3+
'@module-federation/node': patch
4+
---
5+
6+
fix(node): use contenthash instead of chunkhash

.changeset/sour-dragons-hang.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
'@module-federation/modern-js': patch
4+
---
5+
6+
fix(modern-js-plugin): use contenthash instead of chunkhash

apps/node-host/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = composePlugins(withNx(), async (config) => {
99
config.devtool = false;
1010
config.target = 'async-node';
1111
config.output.publicPath = '/testing';
12-
config.output.chunkFilename = '[id]-[chunkhash].js';
12+
config.output.chunkFilename = '[id]-[contenthash].js';
1313
config.optimization.chunkIds = 'named';
1414
await new Promise((r) => setTimeout(r, 400));
1515
config.module.rules.pop();

packages/modernjs/src/cli/configPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export function patchBundlerConfig(options: {
353353
uniqueName &&
354354
!chunkFileName.includes(uniqueName)
355355
) {
356-
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
356+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
357357
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
358358
}
359359
}

packages/nextjs-mf/src/plugins/NextFederationPlugin/apply-server-plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function applyServerPlugins(
6262
): void {
6363
const chunkFileName = compiler.options?.output?.chunkFilename;
6464
const uniqueName = compiler?.options?.output?.uniqueName || options.name;
65-
const suffix = `-[chunkhash].js`;
65+
const suffix = `-[contenthash].js`;
6666

6767
// Modify chunk filename to include a unique suffix if not already present
6868
if (

packages/node/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const { ModuleFederationPlugin } = require('@module-federation/enhanced');
4646
const options = {
4747
target: 'async-node',
4848
output: {
49-
chunkFilename: '[id]-[chunkhash].js', // important to hash chunks
49+
chunkFilename: '[id]-[contenthash].js', // important to hash chunks
5050
},
5151
plugins: [
5252
new ModuleFederationPlugin({

packages/node/src/plugins/NodeFederationPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class NodeFederationPlugin {
8787
uniqueName &&
8888
!chunkFileName.includes(uniqueName)
8989
) {
90-
const suffix = `-[chunkhash].js`;
90+
const suffix = `-[contenthash].js`;
9191
compiler.options.output.chunkFilename = chunkFileName.replace(
9292
'.js',
9393
suffix,

packages/node/src/plugins/UniversalFederationPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class UniversalFederationPlugin {
7171
uniqueName &&
7272
!chunkFileName.includes(uniqueName)
7373
) {
74-
const suffix = `-[chunkhash].js`;
74+
const suffix = `-[contenthash].js`;
7575
compiler.options.output.chunkFilename = chunkFileName.replace(
7676
'.js',
7777
suffix,

packages/rsbuild-plugin/src/utils/ssr.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('patchSSRRspackConfig', () => {
138138
};
139139
const patchedConfig = patchSSRRspackConfig(config, mfConfig, 'ssr');
140140
expect(patchedConfig.output?.chunkFilename).toBe(
141-
'js/[name]myApp-[chunkhash].js',
141+
'js/[name]myApp-[contenthash].js',
142142
);
143143
});
144144

@@ -154,7 +154,7 @@ describe('patchSSRRspackConfig', () => {
154154
const mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions = {}; // No name in mfConfig
155155
const patchedConfig = patchSSRRspackConfig(config, mfConfig, 'ssr');
156156
expect(patchedConfig.output?.chunkFilename).toBe(
157-
'js/[name]myOutputUniqueName-[chunkhash].js',
157+
'js/[name]myOutputUniqueName-[contenthash].js',
158158
);
159159
});
160160

packages/rsbuild-plugin/src/utils/ssr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function patchSSRRspackConfig(
5757
uniqueName &&
5858
!chunkFileName.includes(uniqueName)
5959
) {
60-
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
60+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
6161
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
6262
}
6363

0 commit comments

Comments
 (0)