Skip to content

fix(modern-js-plugin): use contenthash instead of chunkhash #3855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/ninety-points-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/nextjs-mf': patch
'@module-federation/node': patch
---

fix(node): use contenthash instead of chunkhash
6 changes: 6 additions & 0 deletions .changeset/sour-dragons-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/rsbuild-plugin': patch
'@module-federation/modern-js': patch
---

fix(modern-js-plugin): use contenthash instead of chunkhash
2 changes: 1 addition & 1 deletion apps/node-host/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = composePlugins(withNx(), async (config) => {
config.devtool = false;
config.target = 'async-node';
config.output.publicPath = '/testing';
config.output.chunkFilename = '[id]-[chunkhash].js';
config.output.chunkFilename = '[id]-[contenthash].js';
config.optimization.chunkIds = 'named';
await new Promise((r) => setTimeout(r, 400));
config.module.rules.pop();
Expand Down
2 changes: 1 addition & 1 deletion packages/modernjs/src/cli/configPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export function patchBundlerConfig(options: {
uniqueName &&
!chunkFileName.includes(uniqueName)
) {
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function applyServerPlugins(
): void {
const chunkFileName = compiler.options?.output?.chunkFilename;
const uniqueName = compiler?.options?.output?.uniqueName || options.name;
const suffix = `-[chunkhash].js`;
const suffix = `-[contenthash].js`;

// Modify chunk filename to include a unique suffix if not already present
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const { ModuleFederationPlugin } = require('@module-federation/enhanced');
const options = {
target: 'async-node',
output: {
chunkFilename: '[id]-[chunkhash].js', // important to hash chunks
chunkFilename: '[id]-[contenthash].js', // important to hash chunks
},
plugins: [
new ModuleFederationPlugin({
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/plugins/NodeFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NodeFederationPlugin {
uniqueName &&
!chunkFileName.includes(uniqueName)
) {
const suffix = `-[chunkhash].js`;
const suffix = `-[contenthash].js`;
compiler.options.output.chunkFilename = chunkFileName.replace(
'.js',
suffix,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/plugins/UniversalFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class UniversalFederationPlugin {
uniqueName &&
!chunkFileName.includes(uniqueName)
) {
const suffix = `-[chunkhash].js`;
const suffix = `-[contenthash].js`;
compiler.options.output.chunkFilename = chunkFileName.replace(
'.js',
suffix,
Expand Down
4 changes: 2 additions & 2 deletions packages/rsbuild-plugin/src/cli/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('patchSSRRspackConfig', () => {
};
const patchedConfig = patchSSRRspackConfig(config, mfConfig);
expect(patchedConfig.output?.chunkFilename).toBe(
'js/[name]myApp-[chunkhash].js',
'js/[name]myApp-[contenthash].js',
);
});

Expand All @@ -154,7 +154,7 @@ describe('patchSSRRspackConfig', () => {
const mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions = {}; // No name in mfConfig
const patchedConfig = patchSSRRspackConfig(config, mfConfig);
expect(patchedConfig.output?.chunkFilename).toBe(
'js/[name]myOutputUniqueName-[chunkhash].js',
'js/[name]myOutputUniqueName-[contenthash].js',
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/rsbuild-plugin/src/cli/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function patchSSRRspackConfig(
uniqueName &&
!chunkFileName.includes(uniqueName)
) {
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
}

Expand Down
Loading