Skip to content

Commit 75c9912

Browse files
add new output.library.type per Tobias's feedback
1 parent 6e24407 commit 75c9912

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/library/AssignLibraryPlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
9292
* @property {LibraryType} type
9393
* @property {string[] | "global"} prefix name prefix
9494
* @property {string | false} declare declare name as variable
95-
* @property {"error"|"copy"|"assign"} unnamed behavior for unnamed library name
95+
* @property {"error"|"static"|"copy"|"assign"} unnamed behavior for unnamed library name
9696
* @property {"copy"|"assign"=} named behavior for named library name
9797
*/
9898

@@ -267,13 +267,14 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
267267
chunk,
268268
compilation
269269
);
270+
const staticExports = this.unnamed === 'static';
270271
const exportAccess = options.export
271272
? propertyAccess(
272273
Array.isArray(options.export) ? options.export : [options.export]
273274
)
274275
: "";
275276
const result = new ConcatSource(source);
276-
if (options.export === 'static') {
277+
if (staticExports) {
277278
const exportsInfo = moduleGraph.getExportsInfo(module);
278279
for (const exportInfo of exportsInfo.orderedExports) {
279280
if (!exportInfo.provided) continue;

lib/library/EnableLibraryPlugin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ class EnableLibraryPlugin {
167167
}).apply(compiler);
168168
break;
169169
}
170+
case "commonjs-static": {
171+
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
172+
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
173+
new AssignLibraryPlugin({
174+
type,
175+
prefix: ["exports"],
176+
declare: false,
177+
unnamed: "static"
178+
}).apply(compiler);
179+
break;
180+
}
170181
case "commonjs2":
171182
case "commonjs-module": {
172183
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697

schemas/WebpackOptions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@
10101010
"commonjs",
10111011
"commonjs2",
10121012
"commonjs-module",
1013+
"commonjs-static",
10131014
"amd",
10141015
"amd-require",
10151016
"umd",

0 commit comments

Comments
 (0)