webpack 2.3.3 → 2.5.1
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 +148 -133
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +30 -8
- package/lib/CachePlugin.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +6 -3
- package/lib/ChunkRenderError.js +3 -1
- package/lib/ChunkTemplate.js +2 -2
- package/lib/Compilation.js +17 -17
- package/lib/Compiler.js +30 -25
- package/lib/ContextModule.js +4 -3
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +69 -63
- package/lib/DependenciesBlock.js +65 -59
- package/lib/Dependency.js +1 -0
- package/lib/EntryModuleNotFoundError.js +16 -10
- package/lib/ExtendedAPIPlugin.js +7 -2
- package/lib/ExternalModule.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +26 -23
- package/lib/FlagDependencyUsagePlugin.js +63 -75
- package/lib/HotModuleReplacement.runtime.js +25 -27
- package/lib/HotModuleReplacementPlugin.js +3 -5
- package/lib/IgnorePlugin.js +48 -17
- package/lib/JsonpChunkTemplatePlugin.js +24 -24
- package/lib/JsonpMainTemplatePlugin.js +182 -182
- package/lib/LibManifestPlugin.js +51 -46
- package/lib/MainTemplate.js +17 -18
- package/lib/Module.js +158 -160
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +2 -1
- package/lib/ModuleDependencyWarning.js +2 -1
- package/lib/ModuleError.js +2 -2
- package/lib/ModuleFilenameHelpers.js +27 -27
- package/lib/ModuleNotFoundError.js +3 -1
- package/lib/ModuleParseError.js +6 -4
- package/lib/ModuleWarning.js +2 -2
- package/lib/MultiCompiler.js +3 -4
- package/lib/MultiStats.js +3 -3
- package/lib/MultiWatching.js +2 -2
- package/lib/NamedChunksPlugin.js +30 -0
- package/lib/NodeStuffPlugin.js +80 -79
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/RecordIdsPlugin.js +5 -9
- package/lib/SetVarMainTemplatePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +153 -157
- package/lib/Stats.js +34 -6
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/WebpackOptionsValidationError.js +2 -3
- package/lib/dependencies/AMDDefineDependency.js +10 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/ContextDependencyHelpers.js +19 -16
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/DepBlockHelpers.js +3 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportDependenciesBlock.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +16 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
- package/lib/dependencies/RequireEnsureDependency.js +9 -2
- package/lib/formatLocation.js +44 -27
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +2 -2
- package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
- package/lib/performance/NoAsyncChunksWarning.js +5 -1
- package/lib/removeAndDo.js +6 -4
- package/lib/util/identifier.js +16 -0
- package/lib/webpack.js +2 -1
- package/package.json +7 -4
- package/schemas/webpackOptionsSchema.json +35 -0
@@ -2,15 +2,21 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const WebpackError = require("./WebpackError");
|
8
|
+
|
9
|
+
class EntryModuleNotFoundError extends WebpackError {
|
10
|
+
constructor(err) {
|
11
|
+
super();
|
12
|
+
|
13
|
+
this.name = "EntryModuleNotFoundError";
|
14
|
+
this.message = "Entry module not found: " + err;
|
15
|
+
this.details = err.details;
|
16
|
+
this.error = err;
|
17
|
+
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
19
|
+
}
|
12
20
|
}
|
13
|
-
module.exports = EntryModuleNotFoundError;
|
14
21
|
|
15
|
-
|
16
|
-
EntryModuleNotFoundError.prototype.constructor = EntryModuleNotFoundError;
|
22
|
+
module.exports = EntryModuleNotFoundError;
|
package/lib/ExtendedAPIPlugin.js
CHANGED
@@ -9,10 +9,12 @@ const ParserHelpers = require("./ParserHelpers");
|
|
9
9
|
const NullFactory = require("./NullFactory");
|
10
10
|
|
11
11
|
const REPLACEMENTS = {
|
12
|
-
__webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase
|
12
|
+
__webpack_hash__: "__webpack_require__.h", // eslint-disable-line camelcase
|
13
|
+
__webpack_chunkname__: "__webpack_require__.cn" // eslint-disable-line camelcase
|
13
14
|
};
|
14
15
|
const REPLACEMENT_TYPES = {
|
15
|
-
__webpack_hash__: "string" // eslint-disable-line camelcase
|
16
|
+
__webpack_hash__: "string", // eslint-disable-line camelcase
|
17
|
+
__webpack_chunkname__: "string" // eslint-disable-line camelcase
|
16
18
|
};
|
17
19
|
|
18
20
|
class ExtendedAPIPlugin {
|
@@ -25,6 +27,9 @@ class ExtendedAPIPlugin {
|
|
25
27
|
buf.push("");
|
26
28
|
buf.push("// __webpack_hash__");
|
27
29
|
buf.push(`${this.requireFn}.h = ${JSON.stringify(hash)};`);
|
30
|
+
buf.push("");
|
31
|
+
buf.push("// __webpack_chunkname__");
|
32
|
+
buf.push(`${this.requireFn}.cn = ${JSON.stringify(chunk.name)};`);
|
28
33
|
return this.asString(buf);
|
29
34
|
});
|
30
35
|
compilation.mainTemplate.plugin("global-hash", () => true);
|
package/lib/ExternalModule.js
CHANGED
@@ -2,20 +2,21 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
const ExternalModule = require("./ExternalModule");
|
8
|
+
|
9
|
+
class ExternalModuleFactoryPlugin {
|
10
|
+
constructor(type, externals) {
|
11
|
+
this.type = type;
|
12
|
+
this.externals = externals;
|
13
|
+
}
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
var dependency = data.dependencies[0];
|
15
|
+
apply(normalModuleFactory) {
|
16
|
+
const globalType = this.type;
|
17
|
+
normalModuleFactory.plugin("factory", factory => (data, callback) => {
|
18
|
+
const context = data.context;
|
19
|
+
const dependency = data.dependencies[0];
|
19
20
|
|
20
21
|
function handleExternal(value, type, callback) {
|
21
22
|
if(typeof type === "function") {
|
@@ -25,7 +26,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
|
|
25
26
|
if(value === false) return factory(data, callback);
|
26
27
|
if(value === true) value = dependency.request;
|
27
28
|
if(typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
|
28
|
-
|
29
|
+
const idx = value.indexOf(" ");
|
29
30
|
type = value.substr(0, idx);
|
30
31
|
value = value.substr(idx + 1);
|
31
32
|
}
|
@@ -38,13 +39,14 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
|
|
38
39
|
return handleExternal(dependency.request, callback);
|
39
40
|
}
|
40
41
|
} else if(Array.isArray(externals)) {
|
41
|
-
|
42
|
+
let i = 0;
|
42
43
|
(function next() {
|
43
|
-
|
44
|
+
let asyncFlag;
|
45
|
+
const handleExternalsAndCallback = function handleExternalsAndCallback(err, module) {
|
44
46
|
if(err) return callback(err);
|
45
47
|
if(!module) {
|
46
|
-
if(
|
47
|
-
|
48
|
+
if(asyncFlag) {
|
49
|
+
asyncFlag = false;
|
48
50
|
return;
|
49
51
|
}
|
50
52
|
return next();
|
@@ -53,11 +55,11 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
|
|
53
55
|
};
|
54
56
|
|
55
57
|
do {
|
56
|
-
|
58
|
+
asyncFlag = true;
|
57
59
|
if(i >= externals.length) return callback();
|
58
60
|
handleExternals(externals[i++], handleExternalsAndCallback);
|
59
|
-
} while (!
|
60
|
-
|
61
|
+
} while (!asyncFlag); // eslint-disable-line keyword-spacing
|
62
|
+
asyncFlag = false;
|
61
63
|
}());
|
62
64
|
return;
|
63
65
|
} else if(externals instanceof RegExp) {
|
@@ -83,6 +85,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
|
|
83
85
|
if(!module) return handleExternal(false, callback);
|
84
86
|
return callback(null, module);
|
85
87
|
}));
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
}
|
91
|
+
module.exports = ExternalModuleFactoryPlugin;
|
@@ -2,92 +2,80 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
class FlagDependencyUsagePlugin {
|
8
|
+
apply(compiler) {
|
9
|
+
compiler.plugin("compilation", compilation => {
|
10
|
+
compilation.plugin("optimize-modules-advanced", modules => {
|
9
11
|
|
10
|
-
|
11
|
-
compiler.plugin("compilation", function(compilation) {
|
12
|
-
compilation.plugin("optimize-modules-advanced", function(modules) {
|
12
|
+
modules.forEach(module => module.used = false);
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
const queue = [];
|
15
|
+
compilation.chunks.forEach(chunk => {
|
16
|
+
if(chunk.entryModule) {
|
17
|
+
processModule(chunk.entryModule, true);
|
18
|
+
}
|
19
|
+
});
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
processModule(chunk.entryModule, true);
|
21
|
+
while(queue.length) {
|
22
|
+
const queueItem = queue.pop();
|
23
|
+
processDependenciesBlock(queueItem[0], queueItem[1]);
|
22
24
|
}
|
23
|
-
});
|
24
|
-
|
25
|
-
while(queue.length) {
|
26
|
-
var queueItem = queue.pop();
|
27
|
-
processDependenciesBlock(queueItem[0], queueItem[1]);
|
28
|
-
}
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
return;
|
34
|
-
else if(usedExports === true)
|
35
|
-
module.usedExports = true;
|
36
|
-
else if(Array.isArray(usedExports)) {
|
37
|
-
var old = module.usedExports ? module.usedExports.length : -1;
|
38
|
-
module.usedExports = addToSet(module.usedExports || [], usedExports);
|
39
|
-
if(module.usedExports.length === old)
|
26
|
+
function processModule(module, usedExports) {
|
27
|
+
module.used = true;
|
28
|
+
if(module.usedExports === true)
|
40
29
|
return;
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
else if(usedExports === true)
|
31
|
+
module.usedExports = true;
|
32
|
+
else if(Array.isArray(usedExports)) {
|
33
|
+
var old = module.usedExports ? module.usedExports.length : -1;
|
34
|
+
module.usedExports = addToSet(module.usedExports || [], usedExports);
|
35
|
+
if(module.usedExports.length === old)
|
36
|
+
return;
|
37
|
+
} else if(Array.isArray(module.usedExports))
|
38
|
+
return;
|
39
|
+
else
|
40
|
+
module.usedExports = false;
|
48
41
|
|
49
|
-
|
50
|
-
|
51
|
-
processDependency(dep, usedExports);
|
52
|
-
});
|
53
|
-
depBlock.variables.forEach(function(variable) {
|
54
|
-
variable.dependencies.forEach(function(dep) {
|
55
|
-
processDependency(dep, usedExports);
|
56
|
-
});
|
57
|
-
});
|
58
|
-
depBlock.blocks.forEach(function(block) {
|
59
|
-
queue.push([block, usedExports]);
|
60
|
-
});
|
61
|
-
}
|
42
|
+
queue.push([module, module.usedExports]);
|
43
|
+
}
|
62
44
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
var importedNames = reference.importedNames;
|
68
|
-
var oldUsed = module.used;
|
69
|
-
var oldUsedExports = module.usedExports;
|
70
|
-
if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
|
71
|
-
processModule(module, importedNames);
|
45
|
+
function processDependenciesBlock(depBlock, usedExports) {
|
46
|
+
depBlock.dependencies.forEach(dep => processDependency(dep));
|
47
|
+
depBlock.variables.forEach(variable => variable.dependencies.forEach(dep => processDependency(dep)));
|
48
|
+
depBlock.blocks.forEach(block => queue.push([block, usedExports]));
|
72
49
|
}
|
73
|
-
}
|
74
50
|
|
75
|
-
|
51
|
+
function processDependency(dep) {
|
52
|
+
const reference = dep.getReference && dep.getReference();
|
53
|
+
if(!reference) return;
|
54
|
+
const module = reference.module;
|
55
|
+
const importedNames = reference.importedNames;
|
56
|
+
const oldUsed = module.used;
|
57
|
+
const oldUsedExports = module.usedExports;
|
58
|
+
if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
|
59
|
+
processModule(module, importedNames);
|
60
|
+
}
|
61
|
+
}
|
76
62
|
|
77
|
-
function addToSet(a, b) {
|
78
|
-
b.forEach(function(item) {
|
79
|
-
if(a.indexOf(item) < 0)
|
80
|
-
a.push(item);
|
81
63
|
});
|
82
|
-
return a;
|
83
|
-
}
|
84
64
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
65
|
+
function addToSet(a, b) {
|
66
|
+
b.forEach(item => {
|
67
|
+
if(a.indexOf(item) < 0)
|
68
|
+
a.push(item);
|
69
|
+
});
|
70
|
+
return a;
|
71
|
+
}
|
72
|
+
|
73
|
+
function isSubset(biggerSet, subset) {
|
74
|
+
if(biggerSet === true) return true;
|
75
|
+
if(subset === true) return false;
|
76
|
+
return subset.every(item => biggerSet.indexOf(item) >= 0);
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
}
|
81
|
+
module.exports = FlagDependencyUsagePlugin;
|
@@ -8,7 +8,7 @@ module.exports = function() {
|
|
8
8
|
var hotApplyOnUpdate = true;
|
9
9
|
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
10
10
|
var hotCurrentModuleData = {};
|
11
|
-
var
|
11
|
+
var hotCurrentChildModule; // eslint-disable-line no-unused-vars
|
12
12
|
var hotCurrentParents = []; // eslint-disable-line no-unused-vars
|
13
13
|
var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
|
14
14
|
|
@@ -20,14 +20,16 @@ module.exports = function() {
|
|
20
20
|
if(installedModules[request]) {
|
21
21
|
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
22
22
|
installedModules[request].parents.push(moduleId);
|
23
|
-
} else
|
23
|
+
} else {
|
24
|
+
hotCurrentParents = [moduleId];
|
25
|
+
hotCurrentChildModule = request;
|
26
|
+
}
|
24
27
|
if(me.children.indexOf(request) < 0)
|
25
28
|
me.children.push(request);
|
26
29
|
} else {
|
27
30
|
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
28
31
|
hotCurrentParents = [];
|
29
32
|
}
|
30
|
-
hotMainModule = false;
|
31
33
|
return $require$(request);
|
32
34
|
};
|
33
35
|
var ObjectFactory = function ObjectFactory(name) {
|
@@ -43,34 +45,31 @@ module.exports = function() {
|
|
43
45
|
};
|
44
46
|
};
|
45
47
|
for(var name in $require$) {
|
46
|
-
if(Object.prototype.hasOwnProperty.call($require$, name)) {
|
48
|
+
if(Object.prototype.hasOwnProperty.call($require$, name) && name !== "e") {
|
47
49
|
Object.defineProperty(fn, name, ObjectFactory(name));
|
48
50
|
}
|
49
51
|
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
throw err;
|
59
|
-
});
|
52
|
+
fn.e = function(chunkId) {
|
53
|
+
if(hotStatus === "ready")
|
54
|
+
hotSetStatus("prepare");
|
55
|
+
hotChunksLoading++;
|
56
|
+
return $require$.e(chunkId).then(finishChunkLoading, function(err) {
|
57
|
+
finishChunkLoading();
|
58
|
+
throw err;
|
59
|
+
});
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
61
|
+
function finishChunkLoading() {
|
62
|
+
hotChunksLoading--;
|
63
|
+
if(hotStatus === "prepare") {
|
64
|
+
if(!hotWaitingFilesMap[chunkId]) {
|
65
|
+
hotEnsureUpdateChunk(chunkId);
|
66
|
+
}
|
67
|
+
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
68
|
+
hotUpdateDownloaded();
|
70
69
|
}
|
71
70
|
}
|
72
71
|
}
|
73
|
-
}
|
72
|
+
};
|
74
73
|
return fn;
|
75
74
|
}
|
76
75
|
|
@@ -82,7 +81,7 @@ module.exports = function() {
|
|
82
81
|
_selfAccepted: false,
|
83
82
|
_selfDeclined: false,
|
84
83
|
_disposeHandlers: [],
|
85
|
-
_main:
|
84
|
+
_main: hotCurrentChildModule !== moduleId,
|
86
85
|
|
87
86
|
// Module API
|
88
87
|
active: true,
|
@@ -135,7 +134,7 @@ module.exports = function() {
|
|
135
134
|
//inherit from previous dispose call
|
136
135
|
data: hotCurrentModuleData[moduleId]
|
137
136
|
};
|
138
|
-
|
137
|
+
hotCurrentChildModule = undefined;
|
139
138
|
return hot;
|
140
139
|
}
|
141
140
|
|
@@ -173,7 +172,6 @@ module.exports = function() {
|
|
173
172
|
hotSetStatus("idle");
|
174
173
|
return null;
|
175
174
|
}
|
176
|
-
|
177
175
|
hotRequestedFilesMap = {};
|
178
176
|
hotWaitingFilesMap = {};
|
179
177
|
hotAvailableFilesMap = update.c;
|
@@ -109,10 +109,8 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|
109
109
|
c: {}
|
110
110
|
};
|
111
111
|
Object.keys(records.chunkHashs).forEach(function(chunkId) {
|
112
|
-
chunkId = +chunkId;
|
113
|
-
var currentChunk = this.chunks.
|
114
|
-
return chunk.id === chunkId;
|
115
|
-
})[0];
|
112
|
+
chunkId = isNaN(+chunkId) ? chunkId : +chunkId;
|
113
|
+
var currentChunk = this.chunks.find(chunk => chunk.id === chunkId);
|
116
114
|
if(currentChunk) {
|
117
115
|
var newModules = currentChunk.modules.filter(function(module) {
|
118
116
|
return module.hotUpdate;
|
@@ -171,7 +169,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|
171
169
|
hotInitCode
|
172
170
|
.replace(/\$require\$/g, this.requireFn)
|
173
171
|
.replace(/\$hash\$/g, JSON.stringify(hash))
|
174
|
-
.replace(/\/\*foreachInstalledChunks\*\//g, chunk.chunks.length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = " + chunk.id + ";")
|
172
|
+
.replace(/\/\*foreachInstalledChunks\*\//g, chunk.chunks.length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = " + JSON.stringify(chunk.id) + ";")
|
175
173
|
]);
|
176
174
|
});
|
177
175
|
|
package/lib/IgnorePlugin.js
CHANGED
@@ -8,29 +8,60 @@ class IgnorePlugin {
|
|
8
8
|
constructor(resourceRegExp, contextRegExp) {
|
9
9
|
this.resourceRegExp = resourceRegExp;
|
10
10
|
this.contextRegExp = contextRegExp;
|
11
|
+
|
12
|
+
this.checkIgnore = this.checkIgnore.bind(this);
|
13
|
+
}
|
14
|
+
|
15
|
+
/*
|
16
|
+
* Only returns true if a "resourceRegExp" exists
|
17
|
+
* and the resource given matches the regexp.
|
18
|
+
*/
|
19
|
+
checkResource(resource) {
|
20
|
+
if(!this.resourceRegExp) {
|
21
|
+
return false;
|
22
|
+
}
|
23
|
+
return this.resourceRegExp.test(resource);
|
24
|
+
}
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Returns true if contextRegExp does not exist
|
28
|
+
* or if context matches the given regexp.
|
29
|
+
*/
|
30
|
+
checkContext(context) {
|
31
|
+
if(!this.contextRegExp) {
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
return this.contextRegExp.test(context);
|
35
|
+
}
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Returns true if result should be ignored.
|
39
|
+
* false if it shouldn't.
|
40
|
+
*
|
41
|
+
* Not that if "contextRegExp" is given, both the "resourceRegExp"
|
42
|
+
* and "contextRegExp" have to match.
|
43
|
+
*/
|
44
|
+
checkResult(result) {
|
45
|
+
if(!result) {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
return this.checkResource(result.request) && this.checkContext(result.context);
|
49
|
+
}
|
50
|
+
|
51
|
+
checkIgnore(result, callback) {
|
52
|
+
// check if result is ignored
|
53
|
+
if(this.checkResult(result)) {
|
54
|
+
return callback();
|
55
|
+
}
|
56
|
+
return callback(null, result);
|
11
57
|
}
|
12
58
|
|
13
59
|
apply(compiler) {
|
14
|
-
const resourceRegExp = this.resourceRegExp;
|
15
|
-
const contextRegExp = this.contextRegExp;
|
16
60
|
compiler.plugin("normal-module-factory", (nmf) => {
|
17
|
-
nmf.plugin("before-resolve",
|
18
|
-
if(!result) return callback();
|
19
|
-
if(resourceRegExp.test(result.request) &&
|
20
|
-
(!contextRegExp || contextRegExp.test(result.context))) {
|
21
|
-
return callback();
|
22
|
-
}
|
23
|
-
return callback(null, result);
|
24
|
-
});
|
61
|
+
nmf.plugin("before-resolve", this.checkIgnore);
|
25
62
|
});
|
26
63
|
compiler.plugin("context-module-factory", (cmf) => {
|
27
|
-
cmf.plugin("before-resolve",
|
28
|
-
if(!result) return callback();
|
29
|
-
if(resourceRegExp.test(result.request)) {
|
30
|
-
return callback();
|
31
|
-
}
|
32
|
-
return callback(null, result);
|
33
|
-
});
|
64
|
+
cmf.plugin("before-resolve", this.checkIgnore);
|
34
65
|
});
|
35
66
|
}
|
36
67
|
}
|
@@ -2,30 +2,30 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
module.exports = JsonpChunkTemplatePlugin;
|
7
|
+
const ConcatSource = require("webpack-sources").ConcatSource;
|
9
8
|
|
10
|
-
JsonpChunkTemplatePlugin
|
11
|
-
chunkTemplate
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
class JsonpChunkTemplatePlugin {
|
10
|
+
apply(chunkTemplate) {
|
11
|
+
chunkTemplate.plugin("render", function(modules, chunk) {
|
12
|
+
const jsonpFunction = this.outputOptions.jsonpFunction;
|
13
|
+
const source = new ConcatSource();
|
14
|
+
source.add(`${jsonpFunction}(${JSON.stringify(chunk.ids)},`);
|
15
|
+
source.add(modules);
|
16
|
+
const entries = [chunk.entryModule].filter(Boolean).map(m => m.id);
|
17
|
+
if(entries.length > 0) {
|
18
|
+
source.add(`,${JSON.stringify(entries)}`);
|
19
|
+
}
|
20
|
+
source.add(")");
|
21
|
+
return source;
|
22
|
+
});
|
23
|
+
chunkTemplate.plugin("hash", function(hash) {
|
24
|
+
hash.update("JsonpChunkTemplatePlugin");
|
25
|
+
hash.update("3");
|
26
|
+
hash.update(`${this.outputOptions.jsonpFunction}`);
|
27
|
+
hash.update(`${this.outputOptions.library}`);
|
18
28
|
});
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
source.add(")");
|
23
|
-
return source;
|
24
|
-
});
|
25
|
-
chunkTemplate.plugin("hash", function(hash) {
|
26
|
-
hash.update("JsonpChunkTemplatePlugin");
|
27
|
-
hash.update("3");
|
28
|
-
hash.update(this.outputOptions.jsonpFunction + "");
|
29
|
-
hash.update(this.outputOptions.library + "");
|
30
|
-
});
|
31
|
-
};
|
29
|
+
}
|
30
|
+
}
|
31
|
+
module.exports = JsonpChunkTemplatePlugin;
|