Skip to content

Commit 3fcc5dd

Browse files
authored
fix: should not render export in modern-module when iife enabled (#11317)
1 parent 66338f1 commit 3fcc5dd

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

crates/rspack_plugin_library/src/modern_module_library_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async fn render_startup(
225225
}
226226
}
227227

228-
if !exports.is_empty() {
228+
if !exports.is_empty() && !compilation.options.output.iife {
229229
source.add(RawStringSource::from(format!(
230230
"export {{ {} }};\n",
231231
exports.join(", ")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { foo } from './foo.mjs';
2+
console.log('foo: ', foo);
3+
export { foo };
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
entry: {
4+
index: "./index.js"
5+
},
6+
output: {
7+
filename: `[name].js`,
8+
iife: true,
9+
asyncChunks: false,
10+
library: {
11+
type: "modern-module"
12+
}
13+
},
14+
optimization: {
15+
minimize: true,
16+
moduleIds: "named"
17+
},
18+
plugins: [
19+
function () {
20+
/**
21+
* @param {import("@rspack/core").Compilation} compilation compilation
22+
* @returns {void}
23+
*/
24+
const handler = compilation => {
25+
compilation.hooks.afterProcessAssets.tap("testcase", assets => {
26+
const bundle = Object.values(assets)[0]._value;
27+
expect(bundle).toContain(
28+
`(()=>{"use strict";console.log("foo: ","foo")})();`
29+
);
30+
});
31+
};
32+
this.hooks.compilation.tap("testcase", handler);
33+
}
34+
]
35+
};

0 commit comments

Comments
 (0)