diff --git a/packages/rspack-test-tools/tests/configCases/cache/issues-6381/a/a.js b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/a/a.js new file mode 100644 index 00000000000..aef22247d75 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/a/a.js @@ -0,0 +1 @@ +export default 1; diff --git a/packages/rspack-test-tools/tests/configCases/cache/issues-6381/index.js b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/index.js new file mode 100644 index 00000000000..adb1795ef0f --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/index.js @@ -0,0 +1,5 @@ +const a = "a"; +import(`./a/${a}.js`); +it("should work when snapshot.module or snapshot.resolve only set { timestamp: true }", () => { + expect(require("./a/a").default).toBe(1); +}); diff --git a/packages/rspack-test-tools/tests/configCases/cache/issues-6381/webpack.config.js b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/webpack.config.js new file mode 100644 index 00000000000..70b8fda8f68 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/cache/issues-6381/webpack.config.js @@ -0,0 +1,11 @@ +module.exports = { + cache: true, + snapshot: { + module: { + timestamp: true, + }, + resolve: { + timestamp: true, + }, + }, +}; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index e78ee5ad32d..c1a0d9ce80f 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -191,16 +191,26 @@ const applySnapshotDefaults = ( snapshot: SnapshotOptions, { production }: { production: boolean } ) => { - F(snapshot, "module", () => - production - ? { timestamp: true, hash: true } - : { timestamp: true, hash: false } - ); - F(snapshot, "resolve", () => - production - ? { timestamp: true, hash: true } - : { timestamp: true, hash: false } - ); + if (typeof snapshot.module === "object") { + D(snapshot.module, "timestamp", false); + D(snapshot.module, "hash", false); + } else { + F(snapshot, "module", () => + production + ? { timestamp: true, hash: true } + : { timestamp: true, hash: false } + ); + } + if (typeof snapshot.resolve === "object") { + D(snapshot.resolve, "timestamp", false); + D(snapshot.resolve, "hash", false); + } else { + F(snapshot, "resolve", () => + production + ? { timestamp: true, hash: true } + : { timestamp: true, hash: false } + ); + } }; const applyJavascriptParserOptionsDefaults = (