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/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, }, }, }, diff --git a/tests/integration/iife/index.test.ts b/tests/integration/iife/index.test.ts index d3b1c7a3e..a6fa48d00 100644 --- a/tests/integration/iife/index.test.ts +++ b/tests/integration/iife/index.test.ts @@ -14,8 +14,10 @@ test('iife', async () => { }); globalThis.globalHelper = { helperName: 'HELPER_NAME' }; - require(entryFiles.iife); - expect(globalThis.addPrefix('ok')).toBe('production: HELPER_NAMEok'); + await import(entryFiles.iife); + expect(globalThis.addPrefix('ok')).toMatchInlineSnapshot( + `"/tests/integration/iife/dist/iife/index.mjs - production: HELPER_NAMEok"`, + ); delete process.env.NODE_ENV; delete globalThis.globalHelper; @@ -24,7 +26,7 @@ test('iife', async () => { "(()=>{ "use strict"; const external_globalHelper_namespaceObject = globalThis.globalHelper; - const addPrefix = (prefix, str, env)=>\`\${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 344a05ce7..edede7887 100644 --- a/tests/integration/iife/src/utils.ts +++ b/tests/integration/iife/src/utils.ts @@ -1,4 +1,5 @@ -const addPrefix = (prefix: string, str: string, env: string) => - `${env}: ${prefix}${str}`; +const addPrefix = (prefix: string, str: string, env: string): string => { + return `${import.meta.url} - ${env}: ${prefix}${str}`; +}; export { addPrefix };