From 4fc47e370b11aef14e6b187d40a64443ea285246 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 22 Jul 2025 19:44:24 +0800 Subject: [PATCH 1/4] fix: should not throw minify error when using import.meta in iife format --- packages/core/src/config.ts | 9 +++++++++ tests/integration/iife/index.test.ts | 5 ++++- tests/integration/iife/src/utils.ts | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 277df2f0f..43f224624 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -695,6 +695,15 @@ const composeFormatConfig = ({ } const config: EnvironmentConfig = { + output: { + minify: { + jsOptions: { + minimizerOptions: { + module: true, + }, + }, + }, + }, tools: { rspack: { module: { diff --git a/tests/integration/iife/index.test.ts b/tests/integration/iife/index.test.ts index d3b1c7a3e..b69a62e00 100644 --- a/tests/integration/iife/index.test.ts +++ b/tests/integration/iife/index.test.ts @@ -24,7 +24,10 @@ test('iife', async () => { "(()=>{ "use strict"; const external_globalHelper_namespaceObject = globalThis.globalHelper; - const addPrefix = (prefix, str, env)=>\`\${env}: \${prefix}\${str}\`; + const addPrefix = (prefix, str, env)=>{ + console.log(import.meta.dirname); + return \`\${env}: \${prefix}\${str}\`; + }; globalThis.addPrefix = (str)=>addPrefix(external_globalHelper_namespaceObject.helperName, str, "production"); })(); " diff --git a/tests/integration/iife/src/utils.ts b/tests/integration/iife/src/utils.ts index 344a05ce7..9724a0b3f 100644 --- a/tests/integration/iife/src/utils.ts +++ b/tests/integration/iife/src/utils.ts @@ -1,4 +1,6 @@ -const addPrefix = (prefix: string, str: string, env: string) => - `${env}: ${prefix}${str}`; +const addPrefix = (prefix: string, str: string, env: string): string => { + console.log(import.meta.dirname); + return `${env}: ${prefix}${str}`; +}; export { addPrefix }; From 488c8faccc80b831c69814bce635a29fcf5eb393 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 22 Jul 2025 19:50:45 +0800 Subject: [PATCH 2/4] chore: update --- tests/integration/iife/index.test.ts | 9 ++++----- tests/integration/iife/src/utils.ts | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/integration/iife/index.test.ts b/tests/integration/iife/index.test.ts index b69a62e00..b151e568f 100644 --- a/tests/integration/iife/index.test.ts +++ b/tests/integration/iife/index.test.ts @@ -15,7 +15,9 @@ test('iife', async () => { globalThis.globalHelper = { helperName: 'HELPER_NAME' }; require(entryFiles.iife); - expect(globalThis.addPrefix('ok')).toBe('production: HELPER_NAMEok'); + expect(globalThis.addPrefix('ok')).toMatchInlineSnapshot( + `"/tests/integration/iife/dist/iife - production: HELPER_NAMEok"`, + ); delete process.env.NODE_ENV; delete globalThis.globalHelper; @@ -24,10 +26,7 @@ test('iife', async () => { "(()=>{ "use strict"; const external_globalHelper_namespaceObject = globalThis.globalHelper; - const addPrefix = (prefix, str, env)=>{ - console.log(import.meta.dirname); - return \`\${env}: \${prefix}\${str}\`; - }; + const addPrefix = (prefix, str, env)=>\`\${import.meta.dirname} - \${env}: \${prefix}\${str}\`; globalThis.addPrefix = (str)=>addPrefix(external_globalHelper_namespaceObject.helperName, str, "production"); })(); " diff --git a/tests/integration/iife/src/utils.ts b/tests/integration/iife/src/utils.ts index 9724a0b3f..fda03ef73 100644 --- a/tests/integration/iife/src/utils.ts +++ b/tests/integration/iife/src/utils.ts @@ -1,6 +1,5 @@ const addPrefix = (prefix: string, str: string, env: string): string => { - console.log(import.meta.dirname); - return `${env}: ${prefix}${str}`; + return `${import.meta.dirname} - ${env}: ${prefix}${str}`; }; export { addPrefix }; From fa783ce08ebd60b45c8aac119bf9d16054965f7e Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 22 Jul 2025 19:52:56 +0800 Subject: [PATCH 3/4] chore: update --- packages/core/tests/__snapshots__/config.test.ts.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index ed84621f4..7c70d128a 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -856,6 +856,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, "mangle": false, "minify": false, + "module": true, }, }, }, From 6dd5a6c412c013c38d913205da815214dae9d54a Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 22 Jul 2025 20:07:22 +0800 Subject: [PATCH 4/4] chore: update --- tests/integration/iife/index.test.ts | 6 +++--- tests/integration/iife/rslib.config.ts | 3 +++ tests/integration/iife/src/utils.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/iife/index.test.ts b/tests/integration/iife/index.test.ts index b151e568f..a6fa48d00 100644 --- a/tests/integration/iife/index.test.ts +++ b/tests/integration/iife/index.test.ts @@ -14,9 +14,9 @@ test('iife', async () => { }); globalThis.globalHelper = { helperName: 'HELPER_NAME' }; - require(entryFiles.iife); + await import(entryFiles.iife); expect(globalThis.addPrefix('ok')).toMatchInlineSnapshot( - `"/tests/integration/iife/dist/iife - production: HELPER_NAMEok"`, + `"/tests/integration/iife/dist/iife/index.mjs - production: HELPER_NAMEok"`, ); delete process.env.NODE_ENV; delete globalThis.globalHelper; @@ -26,7 +26,7 @@ test('iife', async () => { "(()=>{ "use strict"; const external_globalHelper_namespaceObject = globalThis.globalHelper; - const addPrefix = (prefix, str, env)=>\`\${import.meta.dirname} - \${env}: \${prefix}\${str}\`; + const addPrefix = (prefix, str, env)=>\`\${import.meta.url} - \${env}: \${prefix}\${str}\`; globalThis.addPrefix = (str)=>addPrefix(external_globalHelper_namespaceObject.helperName, str, "production"); })(); " diff --git a/tests/integration/iife/rslib.config.ts b/tests/integration/iife/rslib.config.ts index c795a68d9..ef9935b47 100644 --- a/tests/integration/iife/rslib.config.ts +++ b/tests/integration/iife/rslib.config.ts @@ -6,6 +6,9 @@ export default defineConfig({ generateBundleIifeConfig({ output: { externals: ['globalHelper'], + filename: { + js: '[name].mjs', + }, }, }), ], diff --git a/tests/integration/iife/src/utils.ts b/tests/integration/iife/src/utils.ts index fda03ef73..edede7887 100644 --- a/tests/integration/iife/src/utils.ts +++ b/tests/integration/iife/src/utils.ts @@ -1,5 +1,5 @@ const addPrefix = (prefix: string, str: string, env: string): string => { - return `${import.meta.dirname} - ${env}: ${prefix}${str}`; + return `${import.meta.url} - ${env}: ${prefix}${str}`; }; export { addPrefix };