Skip to content

Commit 102014b

Browse files
committed
fix target expression
fix externals add test case
1 parent 75c9912 commit 102014b

18 files changed

Lines changed: 74 additions & 21 deletions

‎declarations/WebpackOptions.d.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export type LibraryExport = string[] | string;
9595
*/
9696
export type LibraryName = string[] | string | LibraryCustomUmdObject;
9797
/**
98-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
98+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
9999
*/
100100
export type LibraryType =
101101
| (
@@ -110,6 +110,7 @@ export type LibraryType =
110110
| "commonjs"
111111
| "commonjs2"
112112
| "commonjs-module"
113+
| "commonjs-static"
113114
| "amd"
114115
| "amd-require"
115116
| "umd"
@@ -189,6 +190,7 @@ export type ExternalsType =
189190
| "commonjs"
190191
| "commonjs2"
191192
| "commonjs-module"
193+
| "commonjs-static"
192194
| "amd"
193195
| "amd-require"
194196
| "umd"
@@ -1077,7 +1079,7 @@ export interface LibraryOptions {
10771079
*/
10781080
name?: LibraryName;
10791081
/**
1080-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
1082+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
10811083
*/
10821084
type: LibraryType;
10831085
/**
@@ -2061,7 +2063,7 @@ export interface Output {
20612063
*/
20622064
libraryExport?: LibraryExport;
20632065
/**
2064-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
2066+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
20652067
*/
20662068
libraryTarget?: LibraryType;
20672069
/**

‎declarations/plugins/container/ContainerPlugin.d.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type LibraryExport = string[] | string;
2929
*/
3030
export type LibraryName = string[] | string | LibraryCustomUmdObject;
3131
/**
32-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
32+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
3333
*/
3434
export type LibraryType =
3535
| (
@@ -44,6 +44,7 @@ export type LibraryType =
4444
| "commonjs"
4545
| "commonjs2"
4646
| "commonjs-module"
47+
| "commonjs-static"
4748
| "amd"
4849
| "amd-require"
4950
| "umd"
@@ -126,7 +127,7 @@ export interface LibraryOptions {
126127
*/
127128
name?: LibraryName;
128129
/**
129-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
130+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
130131
*/
131132
type: LibraryType;
132133
/**

‎declarations/plugins/container/ContainerReferencePlugin.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type ExternalsType =
1818
| "commonjs"
1919
| "commonjs2"
2020
| "commonjs-module"
21+
| "commonjs-static"
2122
| "amd"
2223
| "amd-require"
2324
| "umd"

‎declarations/plugins/container/ModuleFederationPlugin.d.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type LibraryExport = string[] | string;
2929
*/
3030
export type LibraryName = string[] | string | LibraryCustomUmdObject;
3131
/**
32-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
32+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
3333
*/
3434
export type LibraryType =
3535
| (
@@ -44,6 +44,7 @@ export type LibraryType =
4444
| "commonjs"
4545
| "commonjs2"
4646
| "commonjs-module"
47+
| "commonjs-static"
4748
| "amd"
4849
| "amd-require"
4950
| "umd"
@@ -70,6 +71,7 @@ export type ExternalsType =
7071
| "commonjs"
7172
| "commonjs2"
7273
| "commonjs-module"
74+
| "commonjs-static"
7375
| "amd"
7476
| "amd-require"
7577
| "umd"
@@ -182,7 +184,7 @@ export interface LibraryOptions {
182184
*/
183185
name?: LibraryName;
184186
/**
185-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
187+
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
186188
*/
187189
type: LibraryType;
188190
/**

‎lib/ExternalModule.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ class ExternalModule extends Module {
541541
case "commonjs":
542542
case "commonjs2":
543543
case "commonjs-module":
544+
case "commonjs-static":
544545
return getSourceForCommonJsExternal(request);
545546
case "node-commonjs":
546547
return this.buildInfo.module

‎lib/library/AssignLibraryPlugin.js‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,18 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
261261
* @param {LibraryContext<T>} libraryContext context
262262
* @returns {Source} source with library export
263263
*/
264-
renderStartup(source, module, { moduleGraph, chunk }, { options, compilation }) {
264+
renderStartup(
265+
source,
266+
module,
267+
{ moduleGraph, chunk },
268+
{ options, compilation }
269+
) {
265270
const fullNameResolved = this._getResolvedFullName(
266271
options,
267272
chunk,
268273
compilation
269274
);
270-
const staticExports = this.unnamed === 'static';
275+
const staticExports = this.unnamed === "static";
271276
const exportAccess = options.export
272277
? propertyAccess(
273278
Array.isArray(options.export) ? options.export : [options.export]
@@ -276,14 +281,20 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
276281
const result = new ConcatSource(source);
277282
if (staticExports) {
278283
const exportsInfo = moduleGraph.getExportsInfo(module);
284+
const exportTarget = accessWithInit(
285+
fullNameResolved,
286+
this._getPrefix(compilation).length,
287+
true
288+
);
279289
for (const exportInfo of exportsInfo.orderedExports) {
280290
if (!exportInfo.provided) continue;
291+
const nameAccess = propertyAccess([exportInfo.name]);
281292
result.add(
282-
`module.exports.${exportInfo.name} = ${exportInfo.name};\n`
293+
`${exportTarget}${nameAccess} = __webpack_exports__${exportAccess}${nameAccess};\n`
283294
);
284295
}
285296
result.add(
286-
`Object.defineProperty(module.exports, "__esModule", { value: true });\n`
297+
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
287298
);
288299
} else if (options.name ? this.named === "copy" : this.unnamed === "copy") {
289300
result.add(

‎schemas/WebpackOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/WebpackOptions.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@
18801880
"required": ["type"]
18811881
},
18821882
"LibraryType": {
1883-
"description": "Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).",
1883+
"description": "Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).",
18841884
"anyOf": [
18851885
{
18861886
"enum": [
@@ -1895,6 +1895,7 @@
18951895
"commonjs",
18961896
"commonjs2",
18971897
"commonjs-module",
1898+
"commonjs-static",
18981899
"amd",
18991900
"amd-require",
19001901
"umd",

0 commit comments

Comments
 (0)