webpack 2.2.0-rc.6 → 2.2.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 +39 -63
- package/bin/webpack.js +3 -3
- package/buildin/harmony-module.js +0 -6
- package/buildin/module.js +0 -2
- package/lib/APIPlugin.js +2 -8
- package/lib/AsyncDependenciesBlock.js +46 -55
- package/lib/ChunkTemplate.js +25 -26
- package/lib/CompatibilityPlugin.js +49 -46
- package/lib/Compilation.js +279 -138
- package/lib/Compiler.js +5 -2
- package/lib/ConstPlugin.js +2 -6
- package/lib/DefinePlugin.js +9 -27
- package/lib/EnvironmentPlugin.js +25 -9
- package/lib/EvalDevToolModulePlugin.js +15 -10
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +24 -18
- package/lib/ExtendedAPIPlugin.js +1 -6
- package/lib/FlagDependencyExportsPlugin.js +72 -79
- package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
- package/lib/FunctionModulePlugin.js +17 -11
- package/lib/HotModuleReplacementPlugin.js +3 -13
- package/lib/HotUpdateChunkTemplate.js +21 -22
- package/lib/JsonpTemplatePlugin.js +15 -11
- package/lib/LibManifestPlugin.js +1 -1
- package/lib/LoaderTargetPlugin.js +14 -10
- package/lib/MainTemplate.js +193 -191
- package/lib/MultiWatching.js +16 -14
- package/lib/NoEmitOnErrorsPlugin.js +14 -11
- package/lib/NodeStuffPlugin.js +6 -30
- package/lib/NormalModuleFactory.js +2 -2
- package/lib/NormalModuleReplacementPlugin.js +36 -31
- package/lib/Parser.js +11 -8
- package/lib/ParserHelpers.js +19 -5
- package/lib/ProvidePlugin.js +2 -6
- package/lib/RequestShortener.js +49 -47
- package/lib/RequireJsStuffPlugin.js +5 -20
- package/lib/RuleSet.js +28 -20
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/Template.js +133 -132
- package/lib/compareLocations.js +9 -8
- package/lib/dependencies/AMDPlugin.js +111 -115
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
- package/lib/dependencies/CommonJsPlugin.js +81 -85
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
- package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
- package/lib/dependencies/CriticalDependencyWarning.js +13 -8
- package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
- package/lib/dependencies/ImportParserPlugin.js +31 -28
- package/lib/dependencies/ImportPlugin.js +28 -24
- package/lib/dependencies/LocalModule.js +17 -13
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
- package/lib/dependencies/RequireContextPlugin.js +59 -57
- package/lib/dependencies/RequireEnsurePlugin.js +22 -26
- package/lib/dependencies/RequireIncludePlugin.js +18 -23
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
- package/lib/dependencies/SystemPlugin.js +34 -36
- package/lib/dependencies/WebpackMissingModule.js +10 -18
- package/lib/node/NodeTargetPlugin.js +8 -5
- package/lib/node/NodeWatchFileSystem.js +54 -53
- package/lib/optimize/CommonsChunkPlugin.js +163 -166
- package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
- package/lib/validateSchema.js +18 -18
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
- package/package.json +13 -7
@@ -2,64 +2,65 @@
|
|
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
|
-
this.inputFileSystem = inputFileSystem;
|
9
|
-
this.watcherOptions = {
|
10
|
-
aggregateTimeout: 0
|
11
|
-
};
|
12
|
-
this.watcher = new Watchpack(this.watcherOptions);
|
13
|
-
}
|
7
|
+
const Watchpack = require("watchpack");
|
14
8
|
|
15
|
-
|
9
|
+
class NodeWatchFileSystem {
|
10
|
+
constructor(inputFileSystem) {
|
11
|
+
this.inputFileSystem = inputFileSystem;
|
12
|
+
this.watcherOptions = {
|
13
|
+
aggregateTimeout: 0
|
14
|
+
};
|
15
|
+
this.watcher = new Watchpack(this.watcherOptions);
|
16
|
+
}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
19
|
+
if(!Array.isArray(files))
|
20
|
+
throw new Error("Invalid arguments: 'files'");
|
21
|
+
if(!Array.isArray(dirs))
|
22
|
+
throw new Error("Invalid arguments: 'dirs'");
|
23
|
+
if(!Array.isArray(missing))
|
24
|
+
throw new Error("Invalid arguments: 'missing'");
|
25
|
+
if(typeof callback !== "function")
|
26
|
+
throw new Error("Invalid arguments: 'callback'");
|
27
|
+
if(typeof startTime !== "number" && startTime)
|
28
|
+
throw new Error("Invalid arguments: 'startTime'");
|
29
|
+
if(typeof options !== "object")
|
30
|
+
throw new Error("Invalid arguments: 'options'");
|
31
|
+
if(typeof callbackUndelayed !== "function" && callbackUndelayed)
|
32
|
+
throw new Error("Invalid arguments: 'callbackUndelayed'");
|
33
|
+
const oldWatcher = this.watcher;
|
34
|
+
this.watcher = new Watchpack(options);
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
if(callbackUndelayed)
|
37
|
+
this.watcher.once("change", callbackUndelayed);
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
})
|
48
|
-
return missing.indexOf(file) >= 0;
|
49
|
-
}).sort(), times, times);
|
50
|
-
}.bind(this));
|
39
|
+
this.watcher.once("aggregated", (changes) => {
|
40
|
+
if(this.inputFileSystem && this.inputFileSystem.purge) {
|
41
|
+
this.inputFileSystem.purge(changes);
|
42
|
+
}
|
43
|
+
const times = this.watcher.getTimes();
|
44
|
+
callback(null,
|
45
|
+
changes.filter(file => files.indexOf(file) >= 0).sort(),
|
46
|
+
changes.filter(file => dirs.indexOf(file) >= 0).sort(),
|
47
|
+
changes.filter(file => missing.indexOf(file) >= 0).sort(), times, times);
|
48
|
+
});
|
51
49
|
|
52
|
-
|
50
|
+
this.watcher.watch(files.concat(missing), dirs, startTime);
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
if(oldWatcher) {
|
53
|
+
oldWatcher.close();
|
54
|
+
}
|
55
|
+
return {
|
56
|
+
close: () => {
|
57
|
+
this.watcher.close();
|
58
|
+
},
|
59
|
+
pause: () => {
|
60
|
+
this.watcher.pause();
|
61
|
+
}
|
62
|
+
};
|
56
63
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}.bind(this),
|
61
|
-
pause: function() {
|
62
|
-
this.watcher.pause();
|
63
|
-
}.bind(this)
|
64
|
-
};
|
65
|
-
};
|
64
|
+
}
|
65
|
+
|
66
|
+
module.exports = NodeWatchFileSystem;
|
@@ -2,183 +2,180 @@
|
|
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
|
+
let nextIdent = 0;
|
7
|
+
class CommonsChunkPlugin {
|
8
|
+
constructor(options) {
|
9
|
+
if(arguments.length > 1) {
|
10
|
+
throw new Error(`Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options
|
11
|
+
object *or* the name of the chunk.
|
12
|
+
Example: if your old code looked like this:
|
13
|
+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
|
14
|
+
You would change it to:
|
15
|
+
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js' })
|
16
|
+
The available options are:
|
17
|
+
name: string
|
18
|
+
names: string[]
|
19
|
+
filename: string
|
20
|
+
minChunks: number
|
21
|
+
chunks: string[]
|
22
|
+
children: boolean
|
23
|
+
async: boolean
|
24
|
+
minSize: number`);
|
25
|
+
}
|
6
26
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
" chunks: string[]\n" +
|
21
|
-
" children: boolean\n" +
|
22
|
-
" async: boolean\n" +
|
23
|
-
" minSize: number\n");
|
27
|
+
if(Array.isArray(options) || typeof options === "string") {
|
28
|
+
options = {
|
29
|
+
name: options
|
30
|
+
};
|
31
|
+
}
|
32
|
+
this.chunkNames = options.name || options.names;
|
33
|
+
this.filenameTemplate = options.filename;
|
34
|
+
this.minChunks = options.minChunks;
|
35
|
+
this.selectedChunks = options.chunks;
|
36
|
+
if(options.children) this.selectedChunks = false;
|
37
|
+
this.async = options.async;
|
38
|
+
this.minSize = options.minSize;
|
39
|
+
this.ident = __filename + (nextIdent++);
|
24
40
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
module.exports = CommonsChunkPlugin;
|
41
|
-
CommonsChunkPlugin.prototype.apply = function(compiler) {
|
42
|
-
var chunkNames = this.chunkNames;
|
43
|
-
var filenameTemplate = this.filenameTemplate;
|
44
|
-
var minChunks = this.minChunks;
|
45
|
-
var selectedChunks = this.selectedChunks;
|
46
|
-
var asyncOption = this.async;
|
47
|
-
var minSize = this.minSize;
|
48
|
-
var ident = this.ident;
|
49
|
-
compiler.plugin("this-compilation", function(compilation) {
|
50
|
-
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
|
51
|
-
// only optimize once
|
52
|
-
if(compilation[ident]) return;
|
53
|
-
compilation[ident] = true;
|
41
|
+
apply(compiler) {
|
42
|
+
const chunkNames = this.chunkNames;
|
43
|
+
const filenameTemplate = this.filenameTemplate;
|
44
|
+
const minChunks = this.minChunks;
|
45
|
+
const selectedChunks = this.selectedChunks;
|
46
|
+
const asyncOption = this.async;
|
47
|
+
const minSize = this.minSize;
|
48
|
+
const ident = this.ident;
|
49
|
+
compiler.plugin("this-compilation", (compilation) => {
|
50
|
+
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], (chunks) => {
|
51
|
+
// only optimize once
|
52
|
+
if(compilation[ident]) return;
|
53
|
+
compilation[ident] = true;
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
chunk
|
65
|
-
}
|
66
|
-
return chunk;
|
67
|
-
}, this);
|
68
|
-
} else {
|
69
|
-
throw new Error("Invalid chunkNames argument");
|
70
|
-
}
|
71
|
-
commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
|
72
|
-
var usedChunks;
|
73
|
-
if(Array.isArray(selectedChunks)) {
|
74
|
-
usedChunks = chunks.filter(function(chunk) {
|
75
|
-
if(chunk === commonChunk) return false;
|
76
|
-
return selectedChunks.indexOf(chunk.name) >= 0;
|
77
|
-
});
|
78
|
-
} else if(selectedChunks === false || asyncOption) {
|
79
|
-
usedChunks = (commonChunk.chunks || []).filter(function(chunk) {
|
80
|
-
// we can only move modules from this chunk if the "commonChunk" is the only parent
|
81
|
-
return asyncOption || chunk.parents.length === 1;
|
55
|
+
let commonChunks;
|
56
|
+
if(!chunkNames && (selectedChunks === false || asyncOption)) {
|
57
|
+
commonChunks = chunks;
|
58
|
+
} else if(Array.isArray(chunkNames) || typeof chunkNames === "string") {
|
59
|
+
commonChunks = [].concat(chunkNames).map((chunkName) => {
|
60
|
+
let chunk = chunks.filter((chunk) => chunk.name === chunkName)[0];
|
61
|
+
if(!chunk) {
|
62
|
+
chunk = compilation.addChunk(chunkName);
|
63
|
+
}
|
64
|
+
return chunk;
|
82
65
|
});
|
83
66
|
} else {
|
84
|
-
|
85
|
-
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
|
86
|
-
return;
|
87
|
-
}
|
88
|
-
usedChunks = chunks.filter(function(chunk) {
|
89
|
-
var found = commonChunks.indexOf(chunk);
|
90
|
-
if(found >= idx) return false;
|
91
|
-
return chunk.hasRuntime();
|
92
|
-
});
|
67
|
+
throw new Error("Invalid chunkNames argument");
|
93
68
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
var reallyUsedModules = [];
|
103
|
-
if(minChunks !== Infinity) {
|
104
|
-
var commonModulesCount = [];
|
105
|
-
var commonModules = [];
|
106
|
-
usedChunks.forEach(function(chunk) {
|
107
|
-
chunk.modules.forEach(function(module) {
|
108
|
-
var idx = commonModules.indexOf(module);
|
109
|
-
if(idx < 0) {
|
110
|
-
commonModules.push(module);
|
111
|
-
commonModulesCount.push(1);
|
112
|
-
} else {
|
113
|
-
commonModulesCount[idx]++;
|
114
|
-
}
|
69
|
+
commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
|
70
|
+
let usedChunks;
|
71
|
+
if(Array.isArray(selectedChunks)) {
|
72
|
+
usedChunks = chunks.filter(chunk => chunk !== commonChunk && selectedChunks.indexOf(chunk.name) >= 0);
|
73
|
+
} else if(selectedChunks === false || asyncOption) {
|
74
|
+
usedChunks = (commonChunk.chunks || []).filter((chunk) => {
|
75
|
+
// we can only move modules from this chunk if the "commonChunk" is the only parent
|
76
|
+
return asyncOption || chunk.parents.length === 1;
|
115
77
|
});
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
var module = commonModules[idx];
|
120
|
-
if(typeof minChunks === "function") {
|
121
|
-
if(!minChunks(module, count))
|
122
|
-
return;
|
123
|
-
} else if(count < _minChunks) {
|
78
|
+
} else {
|
79
|
+
if(commonChunk.parents.length > 0) {
|
80
|
+
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
|
124
81
|
return;
|
125
82
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
if(minSize) {
|
132
|
-
var size = reallyUsedModules.reduce(function(a, b) {
|
133
|
-
return a + b.size();
|
134
|
-
}, 0);
|
135
|
-
if(size < minSize)
|
136
|
-
return;
|
137
|
-
}
|
138
|
-
var reallyUsedChunks = [];
|
139
|
-
reallyUsedModules.forEach(function(module) {
|
140
|
-
usedChunks.forEach(function(chunk) {
|
141
|
-
if(module.removeChunk(chunk)) {
|
142
|
-
if(reallyUsedChunks.indexOf(chunk) < 0)
|
143
|
-
reallyUsedChunks.push(chunk);
|
144
|
-
}
|
145
|
-
});
|
146
|
-
commonChunk.addModule(module);
|
147
|
-
module.addChunk(commonChunk);
|
148
|
-
});
|
149
|
-
if(asyncOption) {
|
150
|
-
reallyUsedChunks.forEach(function(chunk) {
|
151
|
-
if(chunk.isInitial())
|
152
|
-
return;
|
153
|
-
chunk.blocks.forEach(function(block) {
|
154
|
-
block.chunks.unshift(commonChunk);
|
155
|
-
commonChunk.addBlock(block);
|
83
|
+
usedChunks = chunks.filter((chunk) => {
|
84
|
+
const found = commonChunks.indexOf(chunk);
|
85
|
+
if(found >= idx) return false;
|
86
|
+
return chunk.hasRuntime();
|
156
87
|
});
|
157
|
-
}
|
158
|
-
asyncChunk
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
88
|
+
}
|
89
|
+
let asyncChunk;
|
90
|
+
if(asyncOption) {
|
91
|
+
asyncChunk = compilation.addChunk(typeof asyncOption === "string" ? asyncOption : undefined);
|
92
|
+
asyncChunk.chunkReason = "async commons chunk";
|
93
|
+
asyncChunk.extraAsync = true;
|
94
|
+
asyncChunk.addParent(commonChunk);
|
95
|
+
commonChunk.addChunk(asyncChunk);
|
96
|
+
commonChunk = asyncChunk;
|
97
|
+
}
|
98
|
+
const reallyUsedModules = [];
|
99
|
+
if(minChunks !== Infinity) {
|
100
|
+
const commonModulesCount = [];
|
101
|
+
const commonModules = [];
|
102
|
+
usedChunks.forEach((chunk) => {
|
103
|
+
chunk.modules.forEach((module) => {
|
104
|
+
const idx = commonModules.indexOf(module);
|
105
|
+
if(idx < 0) {
|
106
|
+
commonModules.push(module);
|
107
|
+
commonModulesCount.push(1);
|
108
|
+
} else {
|
109
|
+
commonModulesCount[idx]++;
|
110
|
+
}
|
111
|
+
});
|
164
112
|
});
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
113
|
+
const _minChunks = (minChunks || Math.max(2, usedChunks.length));
|
114
|
+
commonModulesCount.forEach((count, idx) => {
|
115
|
+
const module = commonModules[idx];
|
116
|
+
if(typeof minChunks === "function") {
|
117
|
+
if(!minChunks(module, count))
|
118
|
+
return;
|
119
|
+
} else if(count < _minChunks) {
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
if(module.chunkCondition && !module.chunkCondition(commonChunk))
|
123
|
+
return;
|
124
|
+
reallyUsedModules.push(module);
|
174
125
|
});
|
175
|
-
|
126
|
+
}
|
127
|
+
if(minSize) {
|
128
|
+
const size = reallyUsedModules.reduce((a, b) => {
|
129
|
+
return a + b.size();
|
130
|
+
}, 0);
|
131
|
+
if(size < minSize)
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
const reallyUsedChunks = new Set();
|
135
|
+
reallyUsedModules.forEach((module) => {
|
136
|
+
usedChunks.forEach((chunk) => {
|
137
|
+
if(module.removeChunk(chunk)) {
|
138
|
+
reallyUsedChunks.add(chunk);
|
139
|
+
}
|
140
|
+
});
|
141
|
+
commonChunk.addModule(module);
|
142
|
+
module.addChunk(commonChunk);
|
176
143
|
});
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
144
|
+
if(asyncOption) {
|
145
|
+
for(const chunk of reallyUsedChunks) {
|
146
|
+
if(chunk.isInitial()) continue;
|
147
|
+
chunk.blocks.forEach((block) => {
|
148
|
+
block.chunks.unshift(commonChunk);
|
149
|
+
commonChunk.addBlock(block);
|
150
|
+
});
|
151
|
+
}
|
152
|
+
asyncChunk.origins = Array.from(reallyUsedChunks).map((chunk) => {
|
153
|
+
return chunk.origins.map((origin) => {
|
154
|
+
const newOrigin = Object.create(origin);
|
155
|
+
newOrigin.reasons = (origin.reasons || []).slice();
|
156
|
+
newOrigin.reasons.push("async commons");
|
157
|
+
return newOrigin;
|
158
|
+
});
|
159
|
+
}).reduce((arr, a) => {
|
160
|
+
arr.push.apply(arr, a);
|
161
|
+
return arr;
|
162
|
+
}, []);
|
163
|
+
} else {
|
164
|
+
usedChunks.forEach((chunk) => {
|
165
|
+
chunk.parents = [commonChunk];
|
166
|
+
chunk.entrypoints.forEach((ep) => {
|
167
|
+
ep.insertChunk(commonChunk, chunk);
|
168
|
+
});
|
169
|
+
commonChunk.addChunk(chunk);
|
170
|
+
});
|
171
|
+
}
|
172
|
+
if(filenameTemplate)
|
173
|
+
commonChunk.filenameTemplate = filenameTemplate;
|
174
|
+
});
|
175
|
+
return true;
|
176
|
+
});
|
182
177
|
});
|
183
|
-
}
|
184
|
-
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
module.exports = CommonsChunkPlugin;
|
@@ -24,32 +24,35 @@ function hasModule(chunk, module, checkedChunks) {
|
|
24
24
|
|
25
25
|
function allHaveModule(someChunks, module, checkedChunks) {
|
26
26
|
if(!checkedChunks) checkedChunks = [];
|
27
|
-
|
27
|
+
var chunks = [];
|
28
28
|
for(var i = 0; i < someChunks.length; i++) {
|
29
29
|
checkedChunks.push(someChunks[i]);
|
30
|
-
|
30
|
+
var subChunks = hasModule(someChunks[i], module, checkedChunks);
|
31
31
|
if(!subChunks) return false;
|
32
|
-
|
32
|
+
|
33
|
+
for(var index = 0; index < subChunks.length; index++) {
|
34
|
+
var item = subChunks[index];
|
35
|
+
|
36
|
+
if(!chunks.length || chunks.indexOf(item) < 0) {
|
37
|
+
chunks.push(item);
|
38
|
+
}
|
39
|
+
}
|
33
40
|
}
|
34
41
|
return chunks;
|
35
42
|
}
|
36
43
|
|
37
|
-
function addToSet(set, items) {
|
38
|
-
items.forEach((item) => {
|
39
|
-
if(set.indexOf(item) < 0)
|
40
|
-
set.push(item);
|
41
|
-
});
|
42
|
-
}
|
43
|
-
|
44
44
|
function debugIds(chunks) {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
var list = [];
|
46
|
+
for(var i = 0; i < chunks.length; i++) {
|
47
|
+
var debugId = chunks[i].debugId;
|
48
|
+
|
49
|
+
if(typeof debugId !== "number") {
|
50
|
+
return "no";
|
51
|
+
}
|
52
|
+
|
53
|
+
list.push(debugId);
|
54
|
+
}
|
55
|
+
|
53
56
|
list.sort();
|
54
57
|
return list.join(",");
|
55
58
|
}
|
@@ -58,13 +61,19 @@ class RemoveParentModulesPlugin {
|
|
58
61
|
apply(compiler) {
|
59
62
|
compiler.plugin("compilation", (compilation) => {
|
60
63
|
compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => {
|
61
|
-
chunks.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
for(var index = 0; index < chunks.length; index++) {
|
65
|
+
var chunk = chunks[index];
|
66
|
+
|
67
|
+
// TODO consider Map when performance has improved https://gist.github.com/sokra/b36098368da7b8f6792fd7c85fca6311
|
68
|
+
var cache = Object.create(null);
|
69
|
+
var modules = chunk.modules.slice();
|
70
|
+
for(var i = 0; i < modules.length; i++) {
|
71
|
+
var module = modules[i];
|
72
|
+
|
73
|
+
if(chunk.parents.length === 0) continue;
|
74
|
+
var dId = debugIds(module.chunks);
|
75
|
+
var parentChunksWithModule;
|
76
|
+
if((dId in cache) && dId !== "no") {
|
68
77
|
parentChunksWithModule = cache[dId];
|
69
78
|
} else {
|
70
79
|
parentChunksWithModule = cache[dId] = allHaveModule(chunk.parents, module);
|
@@ -73,8 +82,8 @@ class RemoveParentModulesPlugin {
|
|
73
82
|
module.rewriteChunkInReasons(chunk, parentChunksWithModule);
|
74
83
|
chunk.removeModule(module);
|
75
84
|
}
|
76
|
-
}
|
77
|
-
}
|
85
|
+
}
|
86
|
+
}
|
78
87
|
});
|
79
88
|
});
|
80
89
|
}
|
package/lib/validateSchema.js
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Gajus Kuizinas @gajus
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const Ajv = require("ajv");
|
8
|
+
const ajv = new Ajv({
|
7
9
|
errorDataPath: "configuration",
|
8
10
|
allErrors: true,
|
9
11
|
verbose: true
|
@@ -12,16 +14,16 @@ require("ajv-keywords")(ajv, ["instanceof"]);
|
|
12
14
|
|
13
15
|
function validateSchema(schema, options) {
|
14
16
|
if(Array.isArray(options)) {
|
15
|
-
|
16
|
-
errors.forEach(
|
17
|
+
const errors = options.map((options) => validateObject(schema, options));
|
18
|
+
errors.forEach((list, idx) => {
|
17
19
|
list.forEach(function applyPrefix(err) {
|
18
|
-
err.dataPath =
|
20
|
+
err.dataPath = `[${idx}]${err.dataPath}`;
|
19
21
|
if(err.children) {
|
20
22
|
err.children.forEach(applyPrefix);
|
21
23
|
}
|
22
24
|
});
|
23
25
|
});
|
24
|
-
return errors.reduce(
|
26
|
+
return errors.reduce((arr, items) => {
|
25
27
|
return arr.concat(items);
|
26
28
|
}, []);
|
27
29
|
} else {
|
@@ -30,22 +32,20 @@ function validateSchema(schema, options) {
|
|
30
32
|
}
|
31
33
|
|
32
34
|
function validateObject(schema, options) {
|
33
|
-
|
34
|
-
|
35
|
+
const validate = ajv.compile(schema);
|
36
|
+
const valid = validate(options);
|
35
37
|
return valid ? [] : filterErrors(validate.errors);
|
36
38
|
}
|
37
39
|
|
38
40
|
function filterErrors(errors) {
|
39
|
-
|
40
|
-
errors.forEach(
|
41
|
-
|
42
|
-
|
43
|
-
newErrors = newErrors.filter(
|
44
|
-
if(oldError.dataPath.
|
41
|
+
let newErrors = [];
|
42
|
+
errors.forEach((err) => {
|
43
|
+
const dataPath = err.dataPath;
|
44
|
+
let children = [];
|
45
|
+
newErrors = newErrors.filter((oldError) => {
|
46
|
+
if(oldError.dataPath.includes(dataPath)) {
|
45
47
|
if(oldError.children) {
|
46
|
-
oldError.children.
|
47
|
-
children.push(child);
|
48
|
-
});
|
48
|
+
children = children.concat(oldError.children.slice(0));
|
49
49
|
}
|
50
50
|
oldError.children = undefined;
|
51
51
|
children.push(oldError);
|
@@ -58,7 +58,7 @@ function filterErrors(errors) {
|
|
58
58
|
}
|
59
59
|
newErrors.push(err);
|
60
60
|
});
|
61
|
-
|
61
|
+
|
62
62
|
return newErrors;
|
63
63
|
}
|
64
64
|
|