webpack 4.1.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,105 +1,105 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const RawSource = require("webpack-sources")
|
8
|
-
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
9
|
-
|
10
|
-
class EvalSourceMapDevToolModuleTemplatePlugin {
|
11
|
-
constructor(compilation, options) {
|
12
|
-
this.compilation = compilation;
|
13
|
-
this.sourceMapComment =
|
14
|
-
options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
|
15
|
-
this.moduleFilenameTemplate =
|
16
|
-
options.moduleFilenameTemplate ||
|
17
|
-
"webpack://[namespace]/[resource-path]?[hash]";
|
18
|
-
this.namespace = options.namespace || "";
|
19
|
-
this.options = options;
|
20
|
-
}
|
21
|
-
|
22
|
-
apply(moduleTemplate) {
|
23
|
-
const self = this;
|
24
|
-
const options = this.options;
|
25
|
-
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
26
|
-
ModuleFilenameHelpers,
|
27
|
-
options
|
28
|
-
);
|
29
|
-
moduleTemplate.hooks.module.tap(
|
30
|
-
"EvalSourceMapDevToolModuleTemplatePlugin",
|
31
|
-
(source, module) => {
|
32
|
-
if (source.__EvalSourceMapDevToolData)
|
33
|
-
return source.__EvalSourceMapDevToolData;
|
34
|
-
if (!matchModule(module.resource)) {
|
35
|
-
return source;
|
36
|
-
}
|
37
|
-
|
38
|
-
let sourceMap;
|
39
|
-
let content;
|
40
|
-
if (source.sourceAndMap) {
|
41
|
-
const sourceAndMap = source.sourceAndMap(options);
|
42
|
-
sourceMap = sourceAndMap.map;
|
43
|
-
content = sourceAndMap.source;
|
44
|
-
} else {
|
45
|
-
sourceMap = source.map(options);
|
46
|
-
content = source.source();
|
47
|
-
}
|
48
|
-
if (!sourceMap) {
|
49
|
-
return source;
|
50
|
-
}
|
51
|
-
|
52
|
-
// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
|
53
|
-
sourceMap = Object.keys(sourceMap).reduce((obj, key) => {
|
54
|
-
obj[key] = sourceMap[key];
|
55
|
-
return obj;
|
56
|
-
}, {});
|
57
|
-
const modules = sourceMap.sources.map(source => {
|
58
|
-
const module = self.compilation.findModule(source);
|
59
|
-
return module || source;
|
60
|
-
});
|
61
|
-
let moduleFilenames = modules.map(module => {
|
62
|
-
return ModuleFilenameHelpers.createFilename(
|
63
|
-
module,
|
64
|
-
{
|
65
|
-
moduleFilenameTemplate: self.moduleFilenameTemplate,
|
66
|
-
namespace: self.namespace
|
67
|
-
},
|
68
|
-
moduleTemplate.runtimeTemplate.requestShortener
|
69
|
-
);
|
70
|
-
});
|
71
|
-
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
72
|
-
moduleFilenames,
|
73
|
-
(filename, i, n) => {
|
74
|
-
for (let j = 0; j < n; j++) filename += "*";
|
75
|
-
return filename;
|
76
|
-
}
|
77
|
-
);
|
78
|
-
sourceMap.sources = moduleFilenames;
|
79
|
-
sourceMap.sourceRoot = options.sourceRoot || "";
|
80
|
-
sourceMap.file = `${module.id}.js`;
|
81
|
-
|
82
|
-
const footer =
|
83
|
-
self.sourceMapComment.replace(
|
84
|
-
/\[url\]/g,
|
85
|
-
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
86
|
-
JSON.stringify(sourceMap),
|
87
|
-
"utf8"
|
88
|
-
).toString("base64")}`
|
89
|
-
) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
|
90
|
-
source.__EvalSourceMapDevToolData = new RawSource(
|
91
|
-
`eval(${JSON.stringify(content + footer)});`
|
92
|
-
);
|
93
|
-
return source.__EvalSourceMapDevToolData;
|
94
|
-
}
|
95
|
-
);
|
96
|
-
moduleTemplate.hooks.hash.tap(
|
97
|
-
"EvalSourceMapDevToolModuleTemplatePlugin",
|
98
|
-
hash => {
|
99
|
-
hash.update("eval-source-map");
|
100
|
-
hash.update("2");
|
101
|
-
}
|
102
|
-
);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { RawSource } = require("webpack-sources");
|
8
|
+
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
9
|
+
|
10
|
+
class EvalSourceMapDevToolModuleTemplatePlugin {
|
11
|
+
constructor(compilation, options) {
|
12
|
+
this.compilation = compilation;
|
13
|
+
this.sourceMapComment =
|
14
|
+
options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
|
15
|
+
this.moduleFilenameTemplate =
|
16
|
+
options.moduleFilenameTemplate ||
|
17
|
+
"webpack://[namespace]/[resource-path]?[hash]";
|
18
|
+
this.namespace = options.namespace || "";
|
19
|
+
this.options = options;
|
20
|
+
}
|
21
|
+
|
22
|
+
apply(moduleTemplate) {
|
23
|
+
const self = this;
|
24
|
+
const options = this.options;
|
25
|
+
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
26
|
+
ModuleFilenameHelpers,
|
27
|
+
options
|
28
|
+
);
|
29
|
+
moduleTemplate.hooks.module.tap(
|
30
|
+
"EvalSourceMapDevToolModuleTemplatePlugin",
|
31
|
+
(source, module) => {
|
32
|
+
if (source.__EvalSourceMapDevToolData)
|
33
|
+
return source.__EvalSourceMapDevToolData;
|
34
|
+
if (!matchModule(module.resource)) {
|
35
|
+
return source;
|
36
|
+
}
|
37
|
+
|
38
|
+
let sourceMap;
|
39
|
+
let content;
|
40
|
+
if (source.sourceAndMap) {
|
41
|
+
const sourceAndMap = source.sourceAndMap(options);
|
42
|
+
sourceMap = sourceAndMap.map;
|
43
|
+
content = sourceAndMap.source;
|
44
|
+
} else {
|
45
|
+
sourceMap = source.map(options);
|
46
|
+
content = source.source();
|
47
|
+
}
|
48
|
+
if (!sourceMap) {
|
49
|
+
return source;
|
50
|
+
}
|
51
|
+
|
52
|
+
// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
|
53
|
+
sourceMap = Object.keys(sourceMap).reduce((obj, key) => {
|
54
|
+
obj[key] = sourceMap[key];
|
55
|
+
return obj;
|
56
|
+
}, {});
|
57
|
+
const modules = sourceMap.sources.map(source => {
|
58
|
+
const module = self.compilation.findModule(source);
|
59
|
+
return module || source;
|
60
|
+
});
|
61
|
+
let moduleFilenames = modules.map(module => {
|
62
|
+
return ModuleFilenameHelpers.createFilename(
|
63
|
+
module,
|
64
|
+
{
|
65
|
+
moduleFilenameTemplate: self.moduleFilenameTemplate,
|
66
|
+
namespace: self.namespace
|
67
|
+
},
|
68
|
+
moduleTemplate.runtimeTemplate.requestShortener
|
69
|
+
);
|
70
|
+
});
|
71
|
+
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
72
|
+
moduleFilenames,
|
73
|
+
(filename, i, n) => {
|
74
|
+
for (let j = 0; j < n; j++) filename += "*";
|
75
|
+
return filename;
|
76
|
+
}
|
77
|
+
);
|
78
|
+
sourceMap.sources = moduleFilenames;
|
79
|
+
sourceMap.sourceRoot = options.sourceRoot || "";
|
80
|
+
sourceMap.file = `${module.id}.js`;
|
81
|
+
|
82
|
+
const footer =
|
83
|
+
self.sourceMapComment.replace(
|
84
|
+
/\[url\]/g,
|
85
|
+
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
86
|
+
JSON.stringify(sourceMap),
|
87
|
+
"utf8"
|
88
|
+
).toString("base64")}`
|
89
|
+
) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
|
90
|
+
source.__EvalSourceMapDevToolData = new RawSource(
|
91
|
+
`eval(${JSON.stringify(content + footer)});`
|
92
|
+
);
|
93
|
+
return source.__EvalSourceMapDevToolData;
|
94
|
+
}
|
95
|
+
);
|
96
|
+
moduleTemplate.hooks.hash.tap(
|
97
|
+
"EvalSourceMapDevToolModuleTemplatePlugin",
|
98
|
+
hash => {
|
99
|
+
hash.update("eval-source-map");
|
100
|
+
hash.update("2");
|
101
|
+
}
|
102
|
+
);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
@@ -1,40 +1,40 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const ConcatSource = require("webpack-sources")
|
8
|
-
|
9
|
-
const accessorToObjectAccess = accessor => {
|
10
|
-
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
11
|
-
};
|
12
|
-
|
13
|
-
class ExportPropertyMainTemplatePlugin {
|
14
|
-
constructor(property) {
|
15
|
-
this.property = property;
|
16
|
-
}
|
17
|
-
|
18
|
-
apply(compilation) {
|
19
|
-
const { mainTemplate, chunkTemplate } = compilation;
|
20
|
-
|
21
|
-
const onRenderWithEntry = (source, chunk, hash) => {
|
22
|
-
const postfix = `${accessorToObjectAccess([].concat(this.property))}`;
|
23
|
-
return new ConcatSource(source, postfix);
|
24
|
-
};
|
25
|
-
|
26
|
-
for (const template of [mainTemplate, chunkTemplate]) {
|
27
|
-
template.hooks.renderWithEntry.tap(
|
28
|
-
"ExportPropertyMainTemplatePlugin",
|
29
|
-
onRenderWithEntry
|
30
|
-
);
|
31
|
-
}
|
32
|
-
|
33
|
-
mainTemplate.hooks.hash.tap("ExportPropertyMainTemplatePlugin", hash => {
|
34
|
-
hash.update("export property");
|
35
|
-
hash.update(`${this.property}`);
|
36
|
-
});
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
module.exports = ExportPropertyMainTemplatePlugin;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { ConcatSource } = require("webpack-sources");
|
8
|
+
|
9
|
+
const accessorToObjectAccess = accessor => {
|
10
|
+
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
11
|
+
};
|
12
|
+
|
13
|
+
class ExportPropertyMainTemplatePlugin {
|
14
|
+
constructor(property) {
|
15
|
+
this.property = property;
|
16
|
+
}
|
17
|
+
|
18
|
+
apply(compilation) {
|
19
|
+
const { mainTemplate, chunkTemplate } = compilation;
|
20
|
+
|
21
|
+
const onRenderWithEntry = (source, chunk, hash) => {
|
22
|
+
const postfix = `${accessorToObjectAccess([].concat(this.property))}`;
|
23
|
+
return new ConcatSource(source, postfix);
|
24
|
+
};
|
25
|
+
|
26
|
+
for (const template of [mainTemplate, chunkTemplate]) {
|
27
|
+
template.hooks.renderWithEntry.tap(
|
28
|
+
"ExportPropertyMainTemplatePlugin",
|
29
|
+
onRenderWithEntry
|
30
|
+
);
|
31
|
+
}
|
32
|
+
|
33
|
+
mainTemplate.hooks.hash.tap("ExportPropertyMainTemplatePlugin", hash => {
|
34
|
+
hash.update("export property");
|
35
|
+
hash.update(`${this.property}`);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
module.exports = ExportPropertyMainTemplatePlugin;
|
package/lib/ExternalModule.js
CHANGED
@@ -1,159 +1,159 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const OriginalSource = require("webpack-sources")
|
8
|
-
const
|
9
|
-
const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
10
|
-
const Template = require("./Template");
|
11
|
-
|
12
|
-
class ExternalModule extends Module {
|
13
|
-
constructor(request, type, userRequest) {
|
14
|
-
super("javascript/dynamic", null);
|
15
|
-
|
16
|
-
// Info from Factory
|
17
|
-
this.request = request;
|
18
|
-
this.externalType = type;
|
19
|
-
this.userRequest = userRequest;
|
20
|
-
this.external = true;
|
21
|
-
}
|
22
|
-
|
23
|
-
libIdent() {
|
24
|
-
return this.userRequest;
|
25
|
-
}
|
26
|
-
|
27
|
-
chunkCondition(chunk) {
|
28
|
-
return chunk.hasEntryModule();
|
29
|
-
}
|
30
|
-
|
31
|
-
identifier() {
|
32
|
-
return "external " + JSON.stringify(this.request);
|
33
|
-
}
|
34
|
-
|
35
|
-
readableIdentifier() {
|
36
|
-
return "external " + JSON.stringify(this.request);
|
37
|
-
}
|
38
|
-
|
39
|
-
needRebuild() {
|
40
|
-
return false;
|
41
|
-
}
|
42
|
-
|
43
|
-
build(options, compilation, resolver, fs, callback) {
|
44
|
-
this.built = true;
|
45
|
-
this.buildMeta = {};
|
46
|
-
this.buildInfo = {};
|
47
|
-
callback();
|
48
|
-
}
|
49
|
-
|
50
|
-
getSourceForGlobalVariableExternal(variableName, type) {
|
51
|
-
if (!Array.isArray(variableName)) {
|
52
|
-
// make it an array as the look up works the same basically
|
53
|
-
variableName = [variableName];
|
54
|
-
}
|
55
|
-
|
56
|
-
// needed for e.g. window["some"]["thing"]
|
57
|
-
const objectLookup = variableName
|
58
|
-
.map(r => `[${JSON.stringify(r)}]`)
|
59
|
-
.join("");
|
60
|
-
return `(function() { module.exports = ${type}${objectLookup}; }());`;
|
61
|
-
}
|
62
|
-
|
63
|
-
getSourceForCommonJsExternal(moduleAndSpecifiers) {
|
64
|
-
if (!Array.isArray(moduleAndSpecifiers)) {
|
65
|
-
return `module.exports = require(${JSON.stringify(
|
66
|
-
moduleAndSpecifiers
|
67
|
-
)});`;
|
68
|
-
}
|
69
|
-
|
70
|
-
const moduleName = moduleAndSpecifiers[0];
|
71
|
-
const objectLookup = moduleAndSpecifiers
|
72
|
-
.slice(1)
|
73
|
-
.map(r => `[${JSON.stringify(r)}]`)
|
74
|
-
.join("");
|
75
|
-
return `module.exports = require(${moduleName})${objectLookup};`;
|
76
|
-
}
|
77
|
-
|
78
|
-
checkExternalVariable(variableToCheck, request) {
|
79
|
-
return `if(typeof ${
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
|
84
|
-
getSourceForAmdOrUmdExternal(id, optional, request) {
|
85
|
-
const externalVariable = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
86
|
-
`${id}`
|
87
|
-
)}__`;
|
88
|
-
const missingModuleError = optional
|
89
|
-
? this.checkExternalVariable(externalVariable, request)
|
90
|
-
: "";
|
91
|
-
return `${missingModuleError}module.exports = ${externalVariable};`;
|
92
|
-
}
|
93
|
-
|
94
|
-
getSourceForDefaultCase(optional, request) {
|
95
|
-
const missingModuleError = optional
|
96
|
-
? this.checkExternalVariable(request, request)
|
97
|
-
: "";
|
98
|
-
return `${missingModuleError}module.exports = ${request};`;
|
99
|
-
}
|
100
|
-
|
101
|
-
getSourceString(runtime) {
|
102
|
-
const request =
|
103
|
-
typeof this.request === "object"
|
104
|
-
? this.request[this.externalType]
|
105
|
-
: this.request;
|
106
|
-
switch (this.externalType) {
|
107
|
-
case "this":
|
108
|
-
case "window":
|
109
|
-
case "self":
|
110
|
-
return this.getSourceForGlobalVariableExternal(
|
111
|
-
request,
|
112
|
-
this.externalType
|
113
|
-
);
|
114
|
-
case "global":
|
115
|
-
return this.getSourceForGlobalVariableExternal(
|
116
|
-
runtime.outputOptions.globalObject,
|
117
|
-
this.externalType
|
118
|
-
);
|
119
|
-
case "commonjs":
|
120
|
-
case "commonjs2":
|
121
|
-
return this.getSourceForCommonJsExternal(request);
|
122
|
-
case "amd":
|
123
|
-
case "umd":
|
124
|
-
case "umd2":
|
125
|
-
return this.getSourceForAmdOrUmdExternal(
|
126
|
-
this.id,
|
127
|
-
this.optional,
|
128
|
-
request
|
129
|
-
);
|
130
|
-
default:
|
131
|
-
return this.getSourceForDefaultCase(this.optional, request);
|
132
|
-
}
|
133
|
-
}
|
134
|
-
|
135
|
-
getSource(sourceString) {
|
136
|
-
if (this.useSourceMap) {
|
137
|
-
return new OriginalSource(sourceString, this.identifier());
|
138
|
-
}
|
139
|
-
|
140
|
-
return new RawSource(sourceString);
|
141
|
-
}
|
142
|
-
|
143
|
-
source(dependencyTemplates, runtime) {
|
144
|
-
return this.getSource(this.getSourceString(runtime));
|
145
|
-
}
|
146
|
-
|
147
|
-
size() {
|
148
|
-
return 42;
|
149
|
-
}
|
150
|
-
|
151
|
-
updateHash(hash) {
|
152
|
-
hash.update(this.externalType);
|
153
|
-
hash.update(JSON.stringify(this.request));
|
154
|
-
hash.update(JSON.stringify(Boolean(this.optional)));
|
155
|
-
super.updateHash(hash);
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
module.exports = ExternalModule;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { OriginalSource, RawSource } = require("webpack-sources");
|
8
|
+
const Module = require("./Module");
|
9
|
+
const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
10
|
+
const Template = require("./Template");
|
11
|
+
|
12
|
+
class ExternalModule extends Module {
|
13
|
+
constructor(request, type, userRequest) {
|
14
|
+
super("javascript/dynamic", null);
|
15
|
+
|
16
|
+
// Info from Factory
|
17
|
+
this.request = request;
|
18
|
+
this.externalType = type;
|
19
|
+
this.userRequest = userRequest;
|
20
|
+
this.external = true;
|
21
|
+
}
|
22
|
+
|
23
|
+
libIdent() {
|
24
|
+
return this.userRequest;
|
25
|
+
}
|
26
|
+
|
27
|
+
chunkCondition(chunk) {
|
28
|
+
return chunk.hasEntryModule();
|
29
|
+
}
|
30
|
+
|
31
|
+
identifier() {
|
32
|
+
return "external " + JSON.stringify(this.request);
|
33
|
+
}
|
34
|
+
|
35
|
+
readableIdentifier() {
|
36
|
+
return "external " + JSON.stringify(this.request);
|
37
|
+
}
|
38
|
+
|
39
|
+
needRebuild() {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
|
43
|
+
build(options, compilation, resolver, fs, callback) {
|
44
|
+
this.built = true;
|
45
|
+
this.buildMeta = {};
|
46
|
+
this.buildInfo = {};
|
47
|
+
callback();
|
48
|
+
}
|
49
|
+
|
50
|
+
getSourceForGlobalVariableExternal(variableName, type) {
|
51
|
+
if (!Array.isArray(variableName)) {
|
52
|
+
// make it an array as the look up works the same basically
|
53
|
+
variableName = [variableName];
|
54
|
+
}
|
55
|
+
|
56
|
+
// needed for e.g. window["some"]["thing"]
|
57
|
+
const objectLookup = variableName
|
58
|
+
.map(r => `[${JSON.stringify(r)}]`)
|
59
|
+
.join("");
|
60
|
+
return `(function() { module.exports = ${type}${objectLookup}; }());`;
|
61
|
+
}
|
62
|
+
|
63
|
+
getSourceForCommonJsExternal(moduleAndSpecifiers) {
|
64
|
+
if (!Array.isArray(moduleAndSpecifiers)) {
|
65
|
+
return `module.exports = require(${JSON.stringify(
|
66
|
+
moduleAndSpecifiers
|
67
|
+
)});`;
|
68
|
+
}
|
69
|
+
|
70
|
+
const moduleName = moduleAndSpecifiers[0];
|
71
|
+
const objectLookup = moduleAndSpecifiers
|
72
|
+
.slice(1)
|
73
|
+
.map(r => `[${JSON.stringify(r)}]`)
|
74
|
+
.join("");
|
75
|
+
return `module.exports = require(${moduleName})${objectLookup};`;
|
76
|
+
}
|
77
|
+
|
78
|
+
checkExternalVariable(variableToCheck, request) {
|
79
|
+
return `if(typeof ${variableToCheck} === 'undefined') {${WebpackMissingModule.moduleCode(
|
80
|
+
request
|
81
|
+
)}}\n`;
|
82
|
+
}
|
83
|
+
|
84
|
+
getSourceForAmdOrUmdExternal(id, optional, request) {
|
85
|
+
const externalVariable = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
86
|
+
`${id}`
|
87
|
+
)}__`;
|
88
|
+
const missingModuleError = optional
|
89
|
+
? this.checkExternalVariable(externalVariable, request)
|
90
|
+
: "";
|
91
|
+
return `${missingModuleError}module.exports = ${externalVariable};`;
|
92
|
+
}
|
93
|
+
|
94
|
+
getSourceForDefaultCase(optional, request) {
|
95
|
+
const missingModuleError = optional
|
96
|
+
? this.checkExternalVariable(request, request)
|
97
|
+
: "";
|
98
|
+
return `${missingModuleError}module.exports = ${request};`;
|
99
|
+
}
|
100
|
+
|
101
|
+
getSourceString(runtime) {
|
102
|
+
const request =
|
103
|
+
typeof this.request === "object"
|
104
|
+
? this.request[this.externalType]
|
105
|
+
: this.request;
|
106
|
+
switch (this.externalType) {
|
107
|
+
case "this":
|
108
|
+
case "window":
|
109
|
+
case "self":
|
110
|
+
return this.getSourceForGlobalVariableExternal(
|
111
|
+
request,
|
112
|
+
this.externalType
|
113
|
+
);
|
114
|
+
case "global":
|
115
|
+
return this.getSourceForGlobalVariableExternal(
|
116
|
+
runtime.outputOptions.globalObject,
|
117
|
+
this.externalType
|
118
|
+
);
|
119
|
+
case "commonjs":
|
120
|
+
case "commonjs2":
|
121
|
+
return this.getSourceForCommonJsExternal(request);
|
122
|
+
case "amd":
|
123
|
+
case "umd":
|
124
|
+
case "umd2":
|
125
|
+
return this.getSourceForAmdOrUmdExternal(
|
126
|
+
this.id,
|
127
|
+
this.optional,
|
128
|
+
request
|
129
|
+
);
|
130
|
+
default:
|
131
|
+
return this.getSourceForDefaultCase(this.optional, request);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
getSource(sourceString) {
|
136
|
+
if (this.useSourceMap) {
|
137
|
+
return new OriginalSource(sourceString, this.identifier());
|
138
|
+
}
|
139
|
+
|
140
|
+
return new RawSource(sourceString);
|
141
|
+
}
|
142
|
+
|
143
|
+
source(dependencyTemplates, runtime) {
|
144
|
+
return this.getSource(this.getSourceString(runtime));
|
145
|
+
}
|
146
|
+
|
147
|
+
size() {
|
148
|
+
return 42;
|
149
|
+
}
|
150
|
+
|
151
|
+
updateHash(hash) {
|
152
|
+
hash.update(this.externalType);
|
153
|
+
hash.update(JSON.stringify(this.request));
|
154
|
+
hash.update(JSON.stringify(Boolean(this.optional)));
|
155
|
+
super.updateHash(hash);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
module.exports = ExternalModule;
|