Skip to content

Commit 8d4c565

Browse files
authored
fix: should not throw minify error when using import.meta in iife output (#1125)
1 parent a0b666a commit 8d4c565

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

packages/core/src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ const composeFormatConfig = ({
695695
}
696696

697697
const config: EnvironmentConfig = {
698+
output: {
699+
minify: {
700+
jsOptions: {
701+
minimizerOptions: {
702+
module: true,
703+
},
704+
},
705+
},
706+
},
698707
tools: {
699708
rspack: {
700709
module: {

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
856856
},
857857
"mangle": false,
858858
"minify": false,
859+
"module": true,
859860
},
860861
},
861862
},

tests/integration/iife/index.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ test('iife', async () => {
1414
});
1515

1616
globalThis.globalHelper = { helperName: 'HELPER_NAME' };
17-
require(entryFiles.iife);
18-
expect(globalThis.addPrefix('ok')).toBe('production: HELPER_NAMEok');
17+
await import(entryFiles.iife);
18+
expect(globalThis.addPrefix('ok')).toMatchInlineSnapshot(
19+
`"<ROOT>/tests/integration/iife/dist/iife/index.mjs - production: HELPER_NAMEok"`,
20+
);
1921
delete process.env.NODE_ENV;
2022
delete globalThis.globalHelper;
2123

@@ -24,7 +26,7 @@ test('iife', async () => {
2426
"(()=>{
2527
"use strict";
2628
const external_globalHelper_namespaceObject = globalThis.globalHelper;
27-
const addPrefix = (prefix, str, env)=>\`\${env}: \${prefix}\${str}\`;
29+
const addPrefix = (prefix, str, env)=>\`\${import.meta.url} - \${env}: \${prefix}\${str}\`;
2830
globalThis.addPrefix = (str)=>addPrefix(external_globalHelper_namespaceObject.helperName, str, "production");
2931
})();
3032
"

tests/integration/iife/rslib.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export default defineConfig({
66
generateBundleIifeConfig({
77
output: {
88
externals: ['globalHelper'],
9+
filename: {
10+
js: '[name].mjs',
11+
},
912
},
1013
}),
1114
],

tests/integration/iife/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const addPrefix = (prefix: string, str: string, env: string) =>
2-
`${env}: ${prefix}${str}`;
1+
const addPrefix = (prefix: string, str: string, env: string): string => {
2+
return `${import.meta.url} - ${env}: ${prefix}${str}`;
3+
};
34

45
export { addPrefix };

0 commit comments

Comments
 (0)