Skip to content

Commit 64a2641

Browse files
committed
support-export-from-entries
1 parent 60d72f6 commit 64a2641

9 files changed

Lines changed: 91 additions & 5 deletions

File tree

‎lib/javascript/JavascriptModulesPlugin.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ class JavascriptModulesPlugin {
11011101
footer = "\n";
11021102
}
11031103
if (exports) {
1104-
if (m !== lastInlinedModule) {
1104+
if (m !== lastInlinedModule && !chunkGraph.isEntryModule(m)) {
11051105
startupSource.add(`var ${m.exportsArgument} = {};\n`);
11061106
} else if (m.exportsArgument !== RuntimeGlobals.exports) {
11071107
startupSource.add(
@@ -1457,19 +1457,25 @@ class JavascriptModulesPlugin {
14571457

14581458
if (chunks.length > 0) {
14591459
buf2.push(
1460-
`${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1460+
`${i === jsEntries.length - 1 ? `var ${RuntimeGlobals.exports} = ` : ""}${
14611461
RuntimeGlobals.onChunksLoaded
14621462
}(undefined, ${JSON.stringify(
14631463
chunks.map((c) => c.id)
14641464
)}, ${runtimeTemplate.returningFunction(
14651465
`${RuntimeGlobals.require}(${moduleIdExpr})`
14661466
)})`
14671467
);
1468+
1469+
buf2.push(
1470+
`${RuntimeGlobals.exports} = Object.assign({...${RuntimeGlobals.exports}},{...${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports})});`
1471+
);
14681472
} else if (useRequire) {
14691473
buf2.push(
1470-
`${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1471-
RuntimeGlobals.require
1472-
}(${moduleIdExpr});`
1474+
`${i === jsEntries.length - 1 ? `var ${RuntimeGlobals.exports} = ` : `${RuntimeGlobals.exports} = `}${
1475+
i === jsEntries.length - 1
1476+
? `${RuntimeGlobals.require}(${moduleIdExpr});`
1477+
: `Object.assign({...${RuntimeGlobals.exports}},{...${RuntimeGlobals.require}(${moduleIdExpr})});`
1478+
}`
14731479
);
14741480
} else {
14751481
if (i === 0) buf2.push(`var ${RuntimeGlobals.exports} = {};`);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
export function indexMethod(){
4+
5+
}

‎test/configCases/entry/issue-15936/node_modules/react.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function scriptAMethod(){
2+
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
export function scriptBMethod(){
4+
5+
}
6+
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
module.exports = {
4+
findBundle() {
5+
return ["./index.js"];
6+
}
7+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {indexMethod} from "./index.js";
2+
import {scriptAMethod} from "./scriptA.js";
3+
import {scriptBMethod} from "./scriptB.js";
4+
import react from "react";
5+
it("exports from all entry modules should be present", function () {
6+
expect(indexMethod).toBeDefined();
7+
expect(scriptAMethod).toBeDefined();
8+
expect(scriptBMethod).toBeDefined();
9+
10+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import react from "react";
2+
it("should have exports from all entry modules", function () {
3+
expect(react).toBe("react");
4+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../types").Configuration} */
4+
module.exports = [
5+
{
6+
entry: {
7+
index: {
8+
import: ["./index.js", "./scriptA.js", "./scriptB.js", "./test.js"]
9+
}
10+
},
11+
target: "web",
12+
output: {
13+
library: {
14+
type: "global"
15+
},
16+
17+
filename: "[name].js"
18+
}
19+
},
20+
{
21+
entry: {
22+
index: {
23+
import: ["./index.js", "./scriptA.js", "./scriptB.js", "./test2.js"]
24+
},
25+
vendors: ["react"]
26+
},
27+
28+
target: "web",
29+
output: {
30+
library: {
31+
type: "global"
32+
},
33+
34+
filename: "[name].js"
35+
},
36+
optimization: {
37+
usedExports: false,
38+
splitChunks: {
39+
chunks: "all"
40+
}
41+
}
42+
}
43+
];

0 commit comments

Comments
 (0)