webpack 2.3.1 → 2.4.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 +139 -132
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- 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 +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -2
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +67 -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/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 +6 -2
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.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 +32 -5
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/WebpackOptionsValidationError.js +8 -4
- 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/HarmonyExportDependencyParserPlugin.js +2 -2
- 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/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +1 -1
- 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 +4 -3
- package/schemas/ajv.absolutePath.js +1 -1
- package/schemas/webpackOptionsSchema.json +27 -0
@@ -2,7 +2,7 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
var
|
5
|
+
var asyncLib = require("async");
|
6
6
|
var path = require("path");
|
7
7
|
|
8
8
|
var Tapable = require("tapable");
|
@@ -61,7 +61,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
61
61
|
|
62
62
|
var resolvers = module.resolvers;
|
63
63
|
|
64
|
-
|
64
|
+
asyncLib.parallel([
|
65
65
|
function(callback) {
|
66
66
|
resolvers.context.resolve({}, context, resource, function(err, result) {
|
67
67
|
if(err) return callback(err);
|
@@ -69,7 +69,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
69
69
|
});
|
70
70
|
},
|
71
71
|
function(callback) {
|
72
|
-
|
72
|
+
asyncLib.map(loaders, function(loader, callback) {
|
73
73
|
resolvers.loader.resolve({}, context, loader, function(err, result) {
|
74
74
|
if(err) return callback(err);
|
75
75
|
callback(null, result);
|
@@ -93,7 +93,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
93
93
|
// Ignored
|
94
94
|
if(!result) return callback();
|
95
95
|
|
96
|
-
return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async));
|
96
|
+
return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async, dependency.chunkName));
|
97
97
|
});
|
98
98
|
});
|
99
99
|
});
|
@@ -106,7 +106,7 @@ ContextModuleFactory.prototype.resolveDependencies = function resolveDependencie
|
|
106
106
|
fs.readdir(directory, function(err, files) {
|
107
107
|
if(err) return callback(err);
|
108
108
|
if(!files || files.length === 0) return callback(null, []);
|
109
|
-
|
109
|
+
asyncLib.map(files.filter(function(p) {
|
110
110
|
return p.indexOf(".") !== 0;
|
111
111
|
}), function(seqment, callback) {
|
112
112
|
|
package/lib/DelegatedModule.js
CHANGED
@@ -2,79 +2,83 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var OriginalSource = require("webpack-sources").OriginalSource;
|
7
|
-
var RawSource = require("webpack-sources").RawSource;
|
8
|
-
var WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
9
|
-
var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
5
|
+
"use strict";
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
const Module = require("./Module");
|
8
|
+
const OriginalSource = require("webpack-sources").OriginalSource;
|
9
|
+
const RawSource = require("webpack-sources").RawSource;
|
10
|
+
const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
11
|
+
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
12
|
+
|
13
|
+
class DelegatedModule extends Module {
|
14
|
+
constructor(sourceRequest, data, type, userRequest) {
|
15
|
+
super();
|
16
|
+
this.sourceRequest = sourceRequest;
|
17
|
+
this.request = data.id;
|
18
|
+
this.meta = data.meta;
|
19
|
+
this.type = type;
|
20
|
+
this.userRequest = userRequest;
|
21
|
+
this.built = false;
|
22
|
+
this.delegated = true;
|
23
|
+
this.delegateData = data;
|
24
|
+
}
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
identifier() {
|
27
|
+
return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
|
28
|
+
}
|
29
|
+
|
30
|
+
readableIdentifier() {
|
31
|
+
return `delegated ${this.userRequest} from ${this.sourceRequest}`;
|
32
|
+
}
|
25
33
|
|
26
|
-
|
34
|
+
needRebuild() {
|
35
|
+
return false;
|
36
|
+
}
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
build(options, compilation, resolver, fs, callback) {
|
39
|
+
this.built = true;
|
40
|
+
this.builtTime = new Date().getTime();
|
41
|
+
this.usedExports = true;
|
42
|
+
this.providedExports = this.delegateData.exports || true;
|
43
|
+
this.dependencies.length = 0;
|
44
|
+
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
45
|
+
callback();
|
46
|
+
}
|
31
47
|
|
32
|
-
|
33
|
-
|
34
|
-
|
48
|
+
unbuild() {
|
49
|
+
this.built = false;
|
50
|
+
super.unbuild();
|
51
|
+
}
|
35
52
|
|
36
|
-
|
37
|
-
|
38
|
-
|
53
|
+
source() {
|
54
|
+
const sourceModule = this.dependencies[0].module;
|
55
|
+
let str;
|
39
56
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
this.providedExports = this.delegateData.exports || true;
|
45
|
-
this.dependencies.length = 0;
|
46
|
-
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
47
|
-
callback();
|
48
|
-
};
|
57
|
+
if(!sourceModule) {
|
58
|
+
str = WebpackMissingModule.moduleCode(this.sourceRequest);
|
59
|
+
} else {
|
60
|
+
str = `module.exports = (__webpack_require__(${sourceModule.id}))`;
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
switch(this.type) {
|
63
|
+
case "require":
|
64
|
+
str += `(${JSON.stringify(this.request)})`;
|
65
|
+
break;
|
66
|
+
case "object":
|
67
|
+
str += `[${JSON.stringify(this.request)}]`;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
}
|
54
71
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
str = WebpackMissingModule.moduleCode(this.sourceRequest);
|
60
|
-
} else {
|
61
|
-
str = "module.exports = (__webpack_require__(" + sourceModule.id + "))";
|
62
|
-
switch(this.type) {
|
63
|
-
case "require":
|
64
|
-
str += "(" + JSON.stringify(this.request) + ");";
|
65
|
-
break;
|
66
|
-
case "object":
|
67
|
-
str += "[" + JSON.stringify(this.request) + "];";
|
68
|
-
break;
|
72
|
+
if(this.useSourceMap) {
|
73
|
+
return new OriginalSource(str, this.identifier());
|
74
|
+
} else {
|
75
|
+
return new RawSource(str);
|
69
76
|
}
|
70
77
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
return new RawSource(str);
|
78
|
+
|
79
|
+
size() {
|
80
|
+
return 42;
|
75
81
|
}
|
76
|
-
}
|
82
|
+
}
|
77
83
|
|
78
|
-
|
79
|
-
return 42;
|
80
|
-
};
|
84
|
+
module.exports = DelegatedModule;
|
package/lib/DependenciesBlock.js
CHANGED
@@ -1,75 +1,81 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
|
4
|
-
*/
|
5
|
-
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
8
|
+
|
9
|
+
function disconnect(i) {
|
10
|
+
i.disconnect();
|
11
11
|
}
|
12
|
-
module.exports = DependenciesBlock;
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
function unseal(i) {
|
14
|
+
i.unseal();
|
15
|
+
}
|
16
|
+
|
17
|
+
class DependenciesBlock {
|
18
|
+
constructor() {
|
19
|
+
this.dependencies = [];
|
20
|
+
this.blocks = [];
|
21
|
+
this.variables = [];
|
22
|
+
}
|
23
|
+
|
24
|
+
addBlock(block) {
|
25
|
+
this.blocks.push(block);
|
26
|
+
block.parent = this;
|
27
|
+
}
|
28
|
+
|
29
|
+
addVariable(name, expression, dependencies) {
|
30
|
+
for(let v of this.variables) {
|
31
|
+
if(v.name === name && v.expression === expression) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
|
36
|
+
}
|
18
37
|
|
19
|
-
|
20
|
-
|
21
|
-
var v = this.variables[i];
|
22
|
-
if(v.name === name && v.expression === expression) return;
|
38
|
+
addDependency(dependency) {
|
39
|
+
this.dependencies.push(dependency);
|
23
40
|
}
|
24
|
-
this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
|
25
|
-
};
|
26
41
|
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
updateHash(hash) {
|
43
|
+
function updateHash(i) {
|
44
|
+
i.updateHash(hash);
|
45
|
+
}
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
this.blocks.forEach(function(b) {
|
36
|
-
b.updateHash(hash);
|
37
|
-
});
|
38
|
-
this.variables.forEach(function(v) {
|
39
|
-
v.updateHash(hash);
|
40
|
-
});
|
41
|
-
};
|
47
|
+
this.dependencies.forEach(updateHash);
|
48
|
+
this.blocks.forEach(updateHash);
|
49
|
+
this.variables.forEach(updateHash);
|
50
|
+
}
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
disconnect() {
|
53
|
+
this.dependencies.forEach(disconnect);
|
54
|
+
this.blocks.forEach(disconnect);
|
55
|
+
this.variables.forEach(disconnect);
|
46
56
|
}
|
47
|
-
this.dependencies.forEach(disconnect);
|
48
|
-
this.blocks.forEach(disconnect);
|
49
|
-
this.variables.forEach(disconnect);
|
50
|
-
};
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
i.unseal();
|
58
|
+
unseal() {
|
59
|
+
this.blocks.forEach(unseal);
|
55
60
|
}
|
56
|
-
this.blocks.forEach(unseal);
|
57
|
-
};
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
hasDependencies(filter) {
|
63
|
+
if(filter) {
|
64
|
+
if(this.dependencies.some(filter)) {
|
65
|
+
return true;
|
66
|
+
}
|
67
|
+
} else {
|
68
|
+
if(this.dependencies.length > 0) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return this.blocks.concat(this.variables).some(item => item.hasDependencies(filter));
|
64
74
|
}
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
}
|
76
|
+
sortItems() {
|
77
|
+
this.blocks.forEach(block => block.sortItems());
|
78
|
+
}
|
79
|
+
}
|
70
80
|
|
71
|
-
|
72
|
-
this.blocks.forEach(function(block) {
|
73
|
-
block.sortItems();
|
74
|
-
});
|
75
|
-
};
|
81
|
+
module.exports = DependenciesBlock;
|
package/lib/Dependency.js
CHANGED
@@ -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);
|
@@ -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;
|