webpack 1.13.3 → 1.14.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/LICENSE +22 -22
- package/README.md +310 -310
- package/buildin/amd-define.js +1 -1
- package/buildin/amd-options.js +1 -1
- package/buildin/module.js +10 -10
- package/hot/dev-server.js +63 -63
- package/hot/log-apply-result.js +25 -25
- package/hot/only-dev-server.js +77 -77
- package/hot/poll.js +37 -37
- package/hot/signal.js +65 -65
- package/lib/APIPlugin.js +49 -49
- package/lib/AbstractPlugin.js +22 -22
- package/lib/AmdMainTemplatePlugin.js +43 -43
- package/lib/ArrayMap.js +50 -50
- package/lib/AsyncDependenciesBlock.js +39 -39
- package/lib/AutomaticPrefetchPlugin.js +35 -35
- package/lib/BannerPlugin.js +34 -34
- package/lib/BasicEvaluatedExpression.js +140 -140
- package/lib/CachePlugin.js +43 -43
- package/lib/CaseSensitiveModulesWarning.js +16 -16
- package/lib/Chunk.js +252 -252
- package/lib/ChunkRenderError.js +17 -17
- package/lib/ChunkTemplate.js +37 -37
- package/lib/CompatibilityPlugin.js +42 -42
- package/lib/Compilation.js +891 -891
- package/lib/Compiler.js +407 -407
- package/lib/ConcatSource.js +5 -5
- package/lib/ConstPlugin.js +54 -54
- package/lib/ContextModule.js +130 -130
- package/lib/ContextModuleFactory.js +132 -132
- package/lib/ContextReplacementPlugin.js +93 -93
- package/lib/CriticalDependenciesWarning.js +24 -24
- package/lib/DefinePlugin.js +126 -126
- package/lib/DelegatedModule.js +69 -69
- package/lib/DelegatedModuleFactoryPlugin.js +51 -51
- package/lib/DelegatedPlugin.js +21 -21
- package/lib/DependenciesBlock.js +57 -57
- package/lib/DependenciesBlockVariable.js +41 -41
- package/lib/Dependency.js +54 -54
- package/lib/DllEntryPlugin.js +32 -32
- package/lib/DllModule.js +55 -55
- package/lib/DllModuleFactory.js +18 -18
- package/lib/DllPlugin.js +30 -30
- package/lib/DllReferencePlugin.js +26 -26
- package/lib/EntryModuleNotFoundError.js +15 -15
- package/lib/EntryOptionPlugin.js +28 -28
- package/lib/EnvironmentPlugin.js +28 -28
- package/lib/EvalDevToolModulePlugin.js +17 -17
- package/lib/EvalDevToolModuleTemplatePlugin.js +29 -29
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +68 -68
- package/lib/EvalSourceMapDevToolPlugin.js +25 -25
- package/lib/ExtendedAPIPlugin.js +45 -45
- package/lib/ExternalModule.js +89 -89
- package/lib/ExternalModuleFactoryPlugin.js +86 -86
- package/lib/ExternalsPlugin.js +16 -16
- package/lib/FunctionModulePlugin.js +18 -18
- package/lib/FunctionModuleTemplatePlugin.js +39 -39
- package/lib/HotModuleReplacement.runtime.js +486 -486
- package/lib/HotModuleReplacementPlugin.js +223 -223
- package/lib/HotUpdateChunkTemplate.js +28 -28
- package/lib/IgnorePlugin.js +32 -32
- package/lib/JsonpChunkTemplatePlugin.js +26 -26
- package/lib/JsonpExportMainTemplatePlugin.js +28 -28
- package/lib/JsonpHotUpdateChunkTemplatePlugin.js +26 -26
- package/lib/JsonpMainTemplate.runtime.js +56 -56
- package/lib/JsonpMainTemplatePlugin.js +162 -162
- package/lib/JsonpTemplatePlugin.js +17 -17
- package/lib/LibManifestPlugin.js +49 -49
- package/lib/LibraryTemplatePlugin.js +77 -77
- package/lib/LoaderTargetPlugin.js +16 -16
- package/lib/MainTemplate.js +169 -169
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +116 -116
- package/lib/ModuleFilenameHelpers.js +157 -157
- package/lib/ModuleNotFoundError.js +17 -17
- package/lib/ModuleParseError.js +26 -26
- package/lib/ModuleParserHelpers.js +21 -21
- package/lib/ModuleReason.js +9 -9
- package/lib/ModuleTemplate.js +23 -23
- package/lib/MovedToPluginWarningPlugin.js +17 -17
- package/lib/MultiCompiler.js +166 -166
- package/lib/MultiEntryPlugin.js +31 -31
- package/lib/MultiModule.js +71 -71
- package/lib/MultiModuleFactory.js +18 -18
- package/lib/NamedModulesPlugin.js +21 -21
- package/lib/NewWatchingPlugin.js +12 -12
- package/lib/NoErrorsPlugin.js +18 -18
- package/lib/NodeStuffPlugin.js +99 -99
- package/lib/NormalModule.js +322 -322
- package/lib/NormalModuleFactory.js +171 -171
- package/lib/NormalModuleReplacementPlugin.js +40 -40
- package/lib/NullFactory.js +10 -10
- package/lib/OldWatchingPlugin.js +14 -14
- package/lib/OptionsApply.js +10 -10
- package/lib/OriginalSource.js +5 -5
- package/lib/Parser.js +938 -938
- package/lib/PrefetchPlugin.js +25 -25
- package/lib/ProgressPlugin.js +80 -80
- package/lib/ProvidePlugin.js +48 -48
- package/lib/RawModule.js +65 -65
- package/lib/RawSource.js +5 -5
- package/lib/RecordIdsPlugin.js +130 -130
- package/lib/RequestShortener.js +56 -56
- package/lib/RequireJsStuffPlugin.js +38 -38
- package/lib/ResolverPlugin.js +34 -34
- package/lib/SetVarMainTemplatePlugin.js +36 -36
- package/lib/SingleEntryPlugin.js +24 -24
- package/lib/Source.js +5 -5
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +33 -33
- package/lib/SourceMapDevToolPlugin.js +168 -168
- package/lib/SourceMapSource.js +5 -5
- package/lib/Stats.js +732 -732
- package/lib/Template.js +119 -119
- package/lib/TemplatedPathPlugin.js +111 -111
- package/lib/UmdMainTemplatePlugin.js +146 -146
- package/lib/UnsupportedFeatureWarning.js +14 -14
- package/lib/WarnCaseSensitiveModulesPlugin.js +27 -27
- package/lib/WatchIgnorePlugin.js +45 -45
- package/lib/WebpackOptionsApply.js +376 -376
- package/lib/WebpackOptionsDefaulter.js +112 -112
- package/lib/dependencies/AMDDefineDependency.js +63 -63
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +240 -240
- package/lib/dependencies/AMDPlugin.js +115 -115
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -34
- package/lib/dependencies/AMDRequireContextDependency.js +18 -18
- package/lib/dependencies/AMDRequireDependenciesBlock.js +25 -25
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +145 -145
- package/lib/dependencies/AMDRequireDependency.js +64 -64
- package/lib/dependencies/AMDRequireItemDependency.js +17 -17
- package/lib/dependencies/CommonJsPlugin.js +93 -93
- package/lib/dependencies/CommonJsRequireContextDependency.js +18 -18
- package/lib/dependencies/CommonJsRequireDependency.js +17 -17
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +91 -91
- package/lib/dependencies/ConstDependency.js +29 -29
- package/lib/dependencies/ContextDependency.js +24 -24
- package/lib/dependencies/ContextDependencyHelpers.js +34 -34
- package/lib/dependencies/ContextDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +31 -31
- package/lib/dependencies/ContextElementDependency.js +17 -17
- package/lib/dependencies/DelegatedSourceDependency.js +14 -14
- package/lib/dependencies/DepBlockHelpers.js +41 -41
- package/lib/dependencies/DllEntryDependency.js +17 -17
- package/lib/dependencies/LabeledExportsDependency.js +21 -21
- package/lib/dependencies/LabeledModuleDependency.js +36 -36
- package/lib/dependencies/LabeledModuleDependencyParserPlugin.js +76 -76
- package/lib/dependencies/LabeledModulesPlugin.js +26 -26
- package/lib/dependencies/LoaderDependency.js +14 -14
- package/lib/dependencies/LoaderPlugin.js +61 -61
- package/lib/dependencies/LocalModule.js +19 -19
- package/lib/dependencies/LocalModuleDependency.js +23 -23
- package/lib/dependencies/LocalModulesHelpers.js +43 -43
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +22 -22
- package/lib/dependencies/ModuleHotAcceptDependency.js +18 -18
- package/lib/dependencies/ModuleHotDeclineDependency.js +18 -18
- package/lib/dependencies/MultiEntryDependency.js +16 -16
- package/lib/dependencies/NullDependency.js +17 -17
- package/lib/dependencies/NullDependencyTemplate.js +8 -8
- package/lib/dependencies/PrefetchDependency.js +14 -14
- package/lib/dependencies/RequireContextDependency.js +17 -17
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +33 -33
- package/lib/dependencies/RequireContextPlugin.js +64 -64
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +20 -20
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +66 -66
- package/lib/dependencies/RequireEnsureDependency.js +29 -29
- package/lib/dependencies/RequireEnsureItemDependency.js +16 -16
- package/lib/dependencies/RequireEnsurePlugin.js +38 -38
- package/lib/dependencies/RequireHeaderDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +18 -18
- package/lib/dependencies/RequireIncludePlugin.js +31 -31
- package/lib/dependencies/RequireResolveContextDependency.js +18 -18
- package/lib/dependencies/RequireResolveDependency.js +17 -17
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +69 -69
- package/lib/dependencies/RequireResolveHeaderDependency.js +25 -25
- package/lib/dependencies/SingleEntryDependency.js +14 -14
- package/lib/dependencies/TemplateArgumentDependency.js +26 -26
- package/lib/dependencies/WebpackMissingModule.js +23 -23
- package/lib/dependencies/getFunctionExpression.js +43 -43
- package/lib/node/NodeChunkTemplatePlugin.js +22 -22
- package/lib/node/NodeEnvironmentPlugin.js +25 -25
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +24 -24
- package/lib/node/NodeMainTemplate.runtime.js +20 -20
- package/lib/node/NodeMainTemplateAsync.runtime.js +34 -34
- package/lib/node/NodeMainTemplatePlugin.js +164 -164
- package/lib/node/NodeOutputFileSystem.js +17 -17
- package/lib/node/NodeSourcePlugin.js +85 -75
- package/lib/node/NodeTargetPlugin.js +12 -12
- package/lib/node/NodeTemplatePlugin.js +21 -21
- package/lib/node/NodeWatchFileSystem.js +65 -65
- package/lib/node/OldNodeWatchFileSystem.js +265 -265
- package/lib/optimize/AggressiveMergingPlugin.js +115 -115
- package/lib/optimize/CommonsChunkPlugin.js +178 -178
- package/lib/optimize/DedupePlugin.js +227 -227
- package/lib/optimize/FlagIncludedChunksPlugin.js +24 -24
- package/lib/optimize/LimitChunkCountPlugin.js +55 -55
- package/lib/optimize/MergeDuplicateChunksPlugin.js +30 -30
- package/lib/optimize/MinChunkSizePlugin.js +61 -61
- package/lib/optimize/OccurenceOrderPlugin.js +5 -5
- package/lib/optimize/OccurrenceOrderPlugin.js +91 -91
- package/lib/optimize/RemoveEmptyChunksPlugin.js +19 -19
- package/lib/optimize/RemoveParentModulesPlugin.js +50 -50
- package/lib/optimize/UglifyJsPlugin.js +146 -146
- package/lib/removeAndDo.js +13 -13
- package/lib/web/WebEnvironmentPlugin.js +16 -16
- package/lib/webpack.js +113 -113
- package/lib/webpack.web.js +27 -27
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +26 -26
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +78 -78
- package/lib/webworker/WebWorkerTemplatePlugin.js +15 -15
- package/package.json +4 -4
package/lib/Compiler.js
CHANGED
@@ -1,407 +1,407 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
var path = require("path");
|
6
|
-
var Tapable = require("tapable");
|
7
|
-
|
8
|
-
var Compilation = require("./Compilation");
|
9
|
-
var Parser = require("./Parser");
|
10
|
-
var Resolver = require("enhanced-resolve/lib/Resolver");
|
11
|
-
|
12
|
-
var NormalModuleFactory = require("./NormalModuleFactory");
|
13
|
-
var ContextModuleFactory = require("./ContextModuleFactory");
|
14
|
-
|
15
|
-
function Watching(compiler, watchOptions, handler) {
|
16
|
-
this.startTime = null;
|
17
|
-
this.invalid = false;
|
18
|
-
this.error = null;
|
19
|
-
this.stats = null;
|
20
|
-
this.handler = handler;
|
21
|
-
if(typeof watchOptions === "number") {
|
22
|
-
this.watchOptions = {
|
23
|
-
aggregateTimeout: watchOptions
|
24
|
-
};
|
25
|
-
} else if(watchOptions && typeof watchOptions === "object") {
|
26
|
-
this.watchOptions = Object.create(watchOptions);
|
27
|
-
} else {
|
28
|
-
this.watchOptions = {};
|
29
|
-
}
|
30
|
-
this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200;
|
31
|
-
this.compiler = compiler;
|
32
|
-
this.running = true;
|
33
|
-
this.compiler.readRecords(function(err) {
|
34
|
-
if(err) return this._done(err);
|
35
|
-
|
36
|
-
this._go();
|
37
|
-
}.bind(this));
|
38
|
-
}
|
39
|
-
|
40
|
-
Watching.prototype._go = function() {
|
41
|
-
this.startTime = new Date().getTime();
|
42
|
-
this.running = true;
|
43
|
-
this.invalid = false;
|
44
|
-
this.compiler.applyPluginsAsync("watch-run", this, function(err) {
|
45
|
-
if(err) return this._done(err);
|
46
|
-
this.compiler.compile(function(err, compilation) {
|
47
|
-
if(err) return this._done(err);
|
48
|
-
if(this.invalid) return this._done();
|
49
|
-
|
50
|
-
if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
|
51
|
-
return this._done(null, compilation);
|
52
|
-
}
|
53
|
-
|
54
|
-
this.compiler.emitAssets(compilation, function(err) {
|
55
|
-
if(err) return this._done(err);
|
56
|
-
if(this.invalid) return this._done();
|
57
|
-
|
58
|
-
this.compiler.emitRecords(function(err) {
|
59
|
-
if(err) return this._done(err);
|
60
|
-
|
61
|
-
return this._done(null, compilation);
|
62
|
-
}.bind(this));
|
63
|
-
}.bind(this));
|
64
|
-
}.bind(this));
|
65
|
-
}.bind(this));
|
66
|
-
};
|
67
|
-
|
68
|
-
Watching.prototype._done = function(err, compilation) {
|
69
|
-
this.running = false;
|
70
|
-
if(this.invalid) return this._go();
|
71
|
-
this.error = err || null;
|
72
|
-
this.stats = compilation ? compilation.getStats() : null;
|
73
|
-
if(this.stats) {
|
74
|
-
this.stats.startTime = this.startTime;
|
75
|
-
this.stats.endTime = new Date().getTime();
|
76
|
-
}
|
77
|
-
if(this.stats)
|
78
|
-
this.compiler.applyPlugins("done", this.stats);
|
79
|
-
else
|
80
|
-
this.compiler.applyPlugins("failed", this.error);
|
81
|
-
this.handler(this.error, this.stats);
|
82
|
-
if(!this.error)
|
83
|
-
this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies);
|
84
|
-
};
|
85
|
-
|
86
|
-
Watching.prototype.watch = function(files, dirs, missing) {
|
87
|
-
this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, function(err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) {
|
88
|
-
this.watcher = null;
|
89
|
-
if(err) return this.handler(err);
|
90
|
-
|
91
|
-
this.compiler.fileTimestamps = fileTimestamps;
|
92
|
-
this.compiler.contextTimestamps = contextTimestamps;
|
93
|
-
this.invalidate();
|
94
|
-
}.bind(this), function() {
|
95
|
-
this.compiler.applyPlugins("invalid");
|
96
|
-
}.bind(this));
|
97
|
-
};
|
98
|
-
|
99
|
-
Watching.prototype.invalidate = function() {
|
100
|
-
if(this.watcher) {
|
101
|
-
this.watcher.pause();
|
102
|
-
this.watcher = null;
|
103
|
-
}
|
104
|
-
if(this.running) {
|
105
|
-
this.invalid = true;
|
106
|
-
return false;
|
107
|
-
} else {
|
108
|
-
this._go();
|
109
|
-
}
|
110
|
-
};
|
111
|
-
|
112
|
-
Watching.prototype.close = function(callback) {
|
113
|
-
if(callback === undefined) callback = function() {};
|
114
|
-
|
115
|
-
if(this.watcher) {
|
116
|
-
this.watcher.close();
|
117
|
-
this.watcher = null;
|
118
|
-
}
|
119
|
-
if(this.running) {
|
120
|
-
this.invalid = true;
|
121
|
-
this._done = function() {
|
122
|
-
callback();
|
123
|
-
};
|
124
|
-
} else {
|
125
|
-
callback();
|
126
|
-
}
|
127
|
-
};
|
128
|
-
|
129
|
-
function Compiler() {
|
130
|
-
Tapable.call(this);
|
131
|
-
|
132
|
-
this.outputPath = "";
|
133
|
-
this.outputFileSystem = null;
|
134
|
-
this.inputFileSystem = null;
|
135
|
-
|
136
|
-
this.recordsInputPath = null;
|
137
|
-
this.recordsOutputPath = null;
|
138
|
-
this.records = {};
|
139
|
-
|
140
|
-
this.fileTimestamps = {};
|
141
|
-
this.contextTimestamps = {};
|
142
|
-
|
143
|
-
this.resolvers = {
|
144
|
-
normal: new Resolver(null),
|
145
|
-
loader: new Resolver(null),
|
146
|
-
context: new Resolver(null)
|
147
|
-
};
|
148
|
-
this.parser = new Parser();
|
149
|
-
|
150
|
-
this.options = {};
|
151
|
-
}
|
152
|
-
module.exports = Compiler;
|
153
|
-
|
154
|
-
Compiler.prototype = Object.create(Tapable.prototype);
|
155
|
-
Compiler.prototype.constructor = Compiler;
|
156
|
-
|
157
|
-
Compiler.Watching = Watching;
|
158
|
-
Compiler.prototype.watch = function(watchOptions, handler) {
|
159
|
-
this.fileTimestamps = {};
|
160
|
-
this.contextTimestamps = {};
|
161
|
-
var watching = new Watching(this, watchOptions, handler);
|
162
|
-
return watching;
|
163
|
-
};
|
164
|
-
|
165
|
-
Compiler.prototype.run = function(callback) {
|
166
|
-
var startTime = new Date().getTime();
|
167
|
-
this.applyPluginsAsync("run", this, function(err) {
|
168
|
-
if(err) return callback(err);
|
169
|
-
|
170
|
-
this.readRecords(function(err) {
|
171
|
-
if(err) return callback(err);
|
172
|
-
|
173
|
-
this.compile(function(err, compilation) {
|
174
|
-
if(err) return callback(err);
|
175
|
-
|
176
|
-
if(this.applyPluginsBailResult("should-emit", compilation) === false) {
|
177
|
-
var stats = compilation.getStats();
|
178
|
-
stats.startTime = startTime;
|
179
|
-
stats.endTime = new Date().getTime();
|
180
|
-
this.applyPlugins("done", stats);
|
181
|
-
return callback(null, stats);
|
182
|
-
}
|
183
|
-
|
184
|
-
this.emitAssets(compilation, function(err) {
|
185
|
-
if(err) return callback(err);
|
186
|
-
|
187
|
-
this.emitRecords(function(err) {
|
188
|
-
if(err) return callback(err);
|
189
|
-
|
190
|
-
var stats = compilation.getStats();
|
191
|
-
stats.startTime = startTime;
|
192
|
-
stats.endTime = new Date().getTime();
|
193
|
-
this.applyPlugins("done", stats);
|
194
|
-
return callback(null, stats);
|
195
|
-
}.bind(this));
|
196
|
-
}.bind(this));
|
197
|
-
}.bind(this));
|
198
|
-
}.bind(this));
|
199
|
-
}.bind(this));
|
200
|
-
};
|
201
|
-
|
202
|
-
Compiler.prototype.runAsChild = function(callback) {
|
203
|
-
this.compile(function(err, compilation) {
|
204
|
-
if(err) return callback(err);
|
205
|
-
|
206
|
-
this.parentCompilation.children.push(compilation);
|
207
|
-
Object.keys(compilation.assets).forEach(function(name) {
|
208
|
-
this.parentCompilation.assets[name] = compilation.assets[name];
|
209
|
-
}.bind(this));
|
210
|
-
|
211
|
-
var entries = compilation.chunks.filter(function(chunk) {
|
212
|
-
return chunk.entry;
|
213
|
-
});
|
214
|
-
return callback(null, entries, compilation);
|
215
|
-
}.bind(this));
|
216
|
-
};
|
217
|
-
|
218
|
-
Compiler.prototype.purgeInputFileSystem = function() {
|
219
|
-
if(this.inputFileSystem && this.inputFileSystem.purge)
|
220
|
-
this.inputFileSystem.purge();
|
221
|
-
};
|
222
|
-
|
223
|
-
Compiler.prototype.emitAssets = function(compilation, callback) {
|
224
|
-
var outputPath;
|
225
|
-
|
226
|
-
this.applyPluginsAsync("emit", compilation, function(err) {
|
227
|
-
if(err) return callback(err);
|
228
|
-
outputPath = compilation.getPath(this.outputPath);
|
229
|
-
this.outputFileSystem.mkdirp(outputPath, emitFiles.bind(this));
|
230
|
-
}.bind(this));
|
231
|
-
|
232
|
-
function emitFiles(err) {
|
233
|
-
if(err) return callback(err);
|
234
|
-
|
235
|
-
require("async").forEach(Object.keys(compilation.assets), function(file, callback) {
|
236
|
-
|
237
|
-
var targetFile = file;
|
238
|
-
var queryStringIdx = targetFile.indexOf("?");
|
239
|
-
if(queryStringIdx >= 0) {
|
240
|
-
targetFile = targetFile.substr(0, queryStringIdx);
|
241
|
-
}
|
242
|
-
|
243
|
-
if(targetFile.match(/\/|\\/)) {
|
244
|
-
var dir = path.dirname(targetFile);
|
245
|
-
this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut.bind(this));
|
246
|
-
} else writeOut.call(this);
|
247
|
-
|
248
|
-
function writeOut(err) {
|
249
|
-
if(err) return callback(err);
|
250
|
-
var targetPath = this.outputFileSystem.join(outputPath, targetFile);
|
251
|
-
var source = compilation.assets[file];
|
252
|
-
if(source.existsAt === targetPath) {
|
253
|
-
source.emitted = false;
|
254
|
-
return callback();
|
255
|
-
}
|
256
|
-
var content = source.source();
|
257
|
-
if(!Buffer.isBuffer(content))
|
258
|
-
content = new Buffer(content, "utf-8");
|
259
|
-
source.existsAt = targetPath;
|
260
|
-
source.emitted = true;
|
261
|
-
this.outputFileSystem.writeFile(targetPath, content, callback);
|
262
|
-
}
|
263
|
-
|
264
|
-
}.bind(this), function(err) {
|
265
|
-
if(err) return callback(err);
|
266
|
-
|
267
|
-
afterEmit.call(this);
|
268
|
-
}.bind(this));
|
269
|
-
}
|
270
|
-
|
271
|
-
function afterEmit() {
|
272
|
-
this.applyPluginsAsync("after-emit", compilation, function(err) {
|
273
|
-
if(err) return callback(err);
|
274
|
-
|
275
|
-
return callback();
|
276
|
-
});
|
277
|
-
}
|
278
|
-
|
279
|
-
};
|
280
|
-
|
281
|
-
Compiler.prototype.emitRecords = function emitRecords(callback) {
|
282
|
-
if(!this.recordsOutputPath) return callback();
|
283
|
-
var idx1 = this.recordsOutputPath.lastIndexOf("/");
|
284
|
-
var idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
285
|
-
var recordsOutputPathDirectory = null;
|
286
|
-
if(idx1 > idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
287
|
-
if(idx1 < idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
288
|
-
if(!recordsOutputPathDirectory) return writeFile.call(this);
|
289
|
-
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, function(err) {
|
290
|
-
if(err) return callback(err);
|
291
|
-
writeFile.call(this);
|
292
|
-
}.bind(this));
|
293
|
-
|
294
|
-
function writeFile() {
|
295
|
-
this.outputFileSystem.writeFile(this.recordsOutputPath, JSON.stringify(this.records, undefined, 2), callback);
|
296
|
-
}
|
297
|
-
};
|
298
|
-
|
299
|
-
Compiler.prototype.readRecords = function readRecords(callback) {
|
300
|
-
if(!this.recordsInputPath) {
|
301
|
-
this.records = {};
|
302
|
-
return callback();
|
303
|
-
}
|
304
|
-
this.inputFileSystem.stat(this.recordsInputPath, function(err) {
|
305
|
-
// It doesn't exist
|
306
|
-
// We can ignore this.
|
307
|
-
if(err) return callback();
|
308
|
-
|
309
|
-
this.inputFileSystem.readFile(this.recordsInputPath, function(err, content) {
|
310
|
-
if(err) return callback(err);
|
311
|
-
|
312
|
-
try {
|
313
|
-
this.records = JSON.parse(content);
|
314
|
-
} catch(e) {
|
315
|
-
e.message = "Cannot parse records: " + e.message;
|
316
|
-
return callback(e);
|
317
|
-
}
|
318
|
-
|
319
|
-
return callback();
|
320
|
-
}.bind(this));
|
321
|
-
}.bind(this));
|
322
|
-
};
|
323
|
-
|
324
|
-
Compiler.prototype.createChildCompiler = function(compilation, compilerName, outputOptions) {
|
325
|
-
var childCompiler = new Compiler();
|
326
|
-
for(var name in this._plugins) {
|
327
|
-
if(["make", "compile", "emit", "after-emit", "invalid", "done", "this-compilation"].indexOf(name) < 0)
|
328
|
-
childCompiler._plugins[name] = this._plugins[name].slice();
|
329
|
-
}
|
330
|
-
childCompiler.name = compilerName;
|
331
|
-
childCompiler.outputPath = this.outputPath;
|
332
|
-
childCompiler.inputFileSystem = this.inputFileSystem;
|
333
|
-
childCompiler.outputFileSystem = null;
|
334
|
-
childCompiler.resolvers = this.resolvers;
|
335
|
-
childCompiler.parser = this.parser;
|
336
|
-
childCompiler.fileTimestamps = this.fileTimestamps;
|
337
|
-
childCompiler.contextTimestamps = this.contextTimestamps;
|
338
|
-
if(!this.records[compilerName]) this.records[compilerName] = [];
|
339
|
-
this.records[compilerName].push(childCompiler.records = {});
|
340
|
-
childCompiler.options = Object.create(this.options);
|
341
|
-
childCompiler.options.output = Object.create(childCompiler.options.output);
|
342
|
-
for(name in outputOptions) {
|
343
|
-
childCompiler.options.output[name] = outputOptions[name];
|
344
|
-
}
|
345
|
-
childCompiler.parentCompilation = compilation;
|
346
|
-
return childCompiler;
|
347
|
-
};
|
348
|
-
|
349
|
-
Compiler.prototype.isChild = function() {
|
350
|
-
return !!this.parentCompilation;
|
351
|
-
};
|
352
|
-
|
353
|
-
Compiler.prototype.createCompilation = function() {
|
354
|
-
return new Compilation(this);
|
355
|
-
};
|
356
|
-
|
357
|
-
Compiler.prototype.newCompilation = function(params) {
|
358
|
-
var compilation = this.createCompilation();
|
359
|
-
compilation.fileTimestamps = this.fileTimestamps;
|
360
|
-
compilation.contextTimestamps = this.contextTimestamps;
|
361
|
-
compilation.name = this.name;
|
362
|
-
compilation.records = this.records;
|
363
|
-
this.applyPlugins("this-compilation", compilation, params);
|
364
|
-
this.applyPlugins("compilation", compilation, params);
|
365
|
-
return compilation;
|
366
|
-
};
|
367
|
-
|
368
|
-
Compiler.prototype.createNormalModuleFactory = function() {
|
369
|
-
var normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.parser, this.options.module || {});
|
370
|
-
this.applyPlugins("normal-module-factory", normalModuleFactory);
|
371
|
-
return normalModuleFactory;
|
372
|
-
};
|
373
|
-
|
374
|
-
Compiler.prototype.createContextModuleFactory = function() {
|
375
|
-
var contextModuleFactory = new ContextModuleFactory(this.resolvers, this.inputFileSystem);
|
376
|
-
this.applyPlugins("context-module-factory", contextModuleFactory);
|
377
|
-
return contextModuleFactory;
|
378
|
-
};
|
379
|
-
|
380
|
-
Compiler.prototype.newCompilationParams = function() {
|
381
|
-
var params = {
|
382
|
-
normalModuleFactory: this.createNormalModuleFactory(),
|
383
|
-
contextModuleFactory: this.createContextModuleFactory()
|
384
|
-
};
|
385
|
-
return params;
|
386
|
-
};
|
387
|
-
|
388
|
-
Compiler.prototype.compile = function(callback) {
|
389
|
-
var params = this.newCompilationParams();
|
390
|
-
this.applyPlugins("compile", params);
|
391
|
-
|
392
|
-
var compilation = this.newCompilation(params);
|
393
|
-
|
394
|
-
this.applyPluginsParallel("make", compilation, function(err) {
|
395
|
-
if(err) return callback(err);
|
396
|
-
|
397
|
-
compilation.seal(function(err) {
|
398
|
-
if(err) return callback(err);
|
399
|
-
|
400
|
-
this.applyPluginsAsync("after-compile", compilation, function(err) {
|
401
|
-
if(err) return callback(err);
|
402
|
-
|
403
|
-
return callback(null, compilation);
|
404
|
-
});
|
405
|
-
}.bind(this));
|
406
|
-
}.bind(this));
|
407
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
var path = require("path");
|
6
|
+
var Tapable = require("tapable");
|
7
|
+
|
8
|
+
var Compilation = require("./Compilation");
|
9
|
+
var Parser = require("./Parser");
|
10
|
+
var Resolver = require("enhanced-resolve/lib/Resolver");
|
11
|
+
|
12
|
+
var NormalModuleFactory = require("./NormalModuleFactory");
|
13
|
+
var ContextModuleFactory = require("./ContextModuleFactory");
|
14
|
+
|
15
|
+
function Watching(compiler, watchOptions, handler) {
|
16
|
+
this.startTime = null;
|
17
|
+
this.invalid = false;
|
18
|
+
this.error = null;
|
19
|
+
this.stats = null;
|
20
|
+
this.handler = handler;
|
21
|
+
if(typeof watchOptions === "number") {
|
22
|
+
this.watchOptions = {
|
23
|
+
aggregateTimeout: watchOptions
|
24
|
+
};
|
25
|
+
} else if(watchOptions && typeof watchOptions === "object") {
|
26
|
+
this.watchOptions = Object.create(watchOptions);
|
27
|
+
} else {
|
28
|
+
this.watchOptions = {};
|
29
|
+
}
|
30
|
+
this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200;
|
31
|
+
this.compiler = compiler;
|
32
|
+
this.running = true;
|
33
|
+
this.compiler.readRecords(function(err) {
|
34
|
+
if(err) return this._done(err);
|
35
|
+
|
36
|
+
this._go();
|
37
|
+
}.bind(this));
|
38
|
+
}
|
39
|
+
|
40
|
+
Watching.prototype._go = function() {
|
41
|
+
this.startTime = new Date().getTime();
|
42
|
+
this.running = true;
|
43
|
+
this.invalid = false;
|
44
|
+
this.compiler.applyPluginsAsync("watch-run", this, function(err) {
|
45
|
+
if(err) return this._done(err);
|
46
|
+
this.compiler.compile(function(err, compilation) {
|
47
|
+
if(err) return this._done(err);
|
48
|
+
if(this.invalid) return this._done();
|
49
|
+
|
50
|
+
if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
|
51
|
+
return this._done(null, compilation);
|
52
|
+
}
|
53
|
+
|
54
|
+
this.compiler.emitAssets(compilation, function(err) {
|
55
|
+
if(err) return this._done(err);
|
56
|
+
if(this.invalid) return this._done();
|
57
|
+
|
58
|
+
this.compiler.emitRecords(function(err) {
|
59
|
+
if(err) return this._done(err);
|
60
|
+
|
61
|
+
return this._done(null, compilation);
|
62
|
+
}.bind(this));
|
63
|
+
}.bind(this));
|
64
|
+
}.bind(this));
|
65
|
+
}.bind(this));
|
66
|
+
};
|
67
|
+
|
68
|
+
Watching.prototype._done = function(err, compilation) {
|
69
|
+
this.running = false;
|
70
|
+
if(this.invalid) return this._go();
|
71
|
+
this.error = err || null;
|
72
|
+
this.stats = compilation ? compilation.getStats() : null;
|
73
|
+
if(this.stats) {
|
74
|
+
this.stats.startTime = this.startTime;
|
75
|
+
this.stats.endTime = new Date().getTime();
|
76
|
+
}
|
77
|
+
if(this.stats)
|
78
|
+
this.compiler.applyPlugins("done", this.stats);
|
79
|
+
else
|
80
|
+
this.compiler.applyPlugins("failed", this.error);
|
81
|
+
this.handler(this.error, this.stats);
|
82
|
+
if(!this.error)
|
83
|
+
this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies);
|
84
|
+
};
|
85
|
+
|
86
|
+
Watching.prototype.watch = function(files, dirs, missing) {
|
87
|
+
this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, function(err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) {
|
88
|
+
this.watcher = null;
|
89
|
+
if(err) return this.handler(err);
|
90
|
+
|
91
|
+
this.compiler.fileTimestamps = fileTimestamps;
|
92
|
+
this.compiler.contextTimestamps = contextTimestamps;
|
93
|
+
this.invalidate();
|
94
|
+
}.bind(this), function() {
|
95
|
+
this.compiler.applyPlugins("invalid");
|
96
|
+
}.bind(this));
|
97
|
+
};
|
98
|
+
|
99
|
+
Watching.prototype.invalidate = function() {
|
100
|
+
if(this.watcher) {
|
101
|
+
this.watcher.pause();
|
102
|
+
this.watcher = null;
|
103
|
+
}
|
104
|
+
if(this.running) {
|
105
|
+
this.invalid = true;
|
106
|
+
return false;
|
107
|
+
} else {
|
108
|
+
this._go();
|
109
|
+
}
|
110
|
+
};
|
111
|
+
|
112
|
+
Watching.prototype.close = function(callback) {
|
113
|
+
if(callback === undefined) callback = function() {};
|
114
|
+
|
115
|
+
if(this.watcher) {
|
116
|
+
this.watcher.close();
|
117
|
+
this.watcher = null;
|
118
|
+
}
|
119
|
+
if(this.running) {
|
120
|
+
this.invalid = true;
|
121
|
+
this._done = function() {
|
122
|
+
callback();
|
123
|
+
};
|
124
|
+
} else {
|
125
|
+
callback();
|
126
|
+
}
|
127
|
+
};
|
128
|
+
|
129
|
+
function Compiler() {
|
130
|
+
Tapable.call(this);
|
131
|
+
|
132
|
+
this.outputPath = "";
|
133
|
+
this.outputFileSystem = null;
|
134
|
+
this.inputFileSystem = null;
|
135
|
+
|
136
|
+
this.recordsInputPath = null;
|
137
|
+
this.recordsOutputPath = null;
|
138
|
+
this.records = {};
|
139
|
+
|
140
|
+
this.fileTimestamps = {};
|
141
|
+
this.contextTimestamps = {};
|
142
|
+
|
143
|
+
this.resolvers = {
|
144
|
+
normal: new Resolver(null),
|
145
|
+
loader: new Resolver(null),
|
146
|
+
context: new Resolver(null)
|
147
|
+
};
|
148
|
+
this.parser = new Parser();
|
149
|
+
|
150
|
+
this.options = {};
|
151
|
+
}
|
152
|
+
module.exports = Compiler;
|
153
|
+
|
154
|
+
Compiler.prototype = Object.create(Tapable.prototype);
|
155
|
+
Compiler.prototype.constructor = Compiler;
|
156
|
+
|
157
|
+
Compiler.Watching = Watching;
|
158
|
+
Compiler.prototype.watch = function(watchOptions, handler) {
|
159
|
+
this.fileTimestamps = {};
|
160
|
+
this.contextTimestamps = {};
|
161
|
+
var watching = new Watching(this, watchOptions, handler);
|
162
|
+
return watching;
|
163
|
+
};
|
164
|
+
|
165
|
+
Compiler.prototype.run = function(callback) {
|
166
|
+
var startTime = new Date().getTime();
|
167
|
+
this.applyPluginsAsync("run", this, function(err) {
|
168
|
+
if(err) return callback(err);
|
169
|
+
|
170
|
+
this.readRecords(function(err) {
|
171
|
+
if(err) return callback(err);
|
172
|
+
|
173
|
+
this.compile(function(err, compilation) {
|
174
|
+
if(err) return callback(err);
|
175
|
+
|
176
|
+
if(this.applyPluginsBailResult("should-emit", compilation) === false) {
|
177
|
+
var stats = compilation.getStats();
|
178
|
+
stats.startTime = startTime;
|
179
|
+
stats.endTime = new Date().getTime();
|
180
|
+
this.applyPlugins("done", stats);
|
181
|
+
return callback(null, stats);
|
182
|
+
}
|
183
|
+
|
184
|
+
this.emitAssets(compilation, function(err) {
|
185
|
+
if(err) return callback(err);
|
186
|
+
|
187
|
+
this.emitRecords(function(err) {
|
188
|
+
if(err) return callback(err);
|
189
|
+
|
190
|
+
var stats = compilation.getStats();
|
191
|
+
stats.startTime = startTime;
|
192
|
+
stats.endTime = new Date().getTime();
|
193
|
+
this.applyPlugins("done", stats);
|
194
|
+
return callback(null, stats);
|
195
|
+
}.bind(this));
|
196
|
+
}.bind(this));
|
197
|
+
}.bind(this));
|
198
|
+
}.bind(this));
|
199
|
+
}.bind(this));
|
200
|
+
};
|
201
|
+
|
202
|
+
Compiler.prototype.runAsChild = function(callback) {
|
203
|
+
this.compile(function(err, compilation) {
|
204
|
+
if(err) return callback(err);
|
205
|
+
|
206
|
+
this.parentCompilation.children.push(compilation);
|
207
|
+
Object.keys(compilation.assets).forEach(function(name) {
|
208
|
+
this.parentCompilation.assets[name] = compilation.assets[name];
|
209
|
+
}.bind(this));
|
210
|
+
|
211
|
+
var entries = compilation.chunks.filter(function(chunk) {
|
212
|
+
return chunk.entry;
|
213
|
+
});
|
214
|
+
return callback(null, entries, compilation);
|
215
|
+
}.bind(this));
|
216
|
+
};
|
217
|
+
|
218
|
+
Compiler.prototype.purgeInputFileSystem = function() {
|
219
|
+
if(this.inputFileSystem && this.inputFileSystem.purge)
|
220
|
+
this.inputFileSystem.purge();
|
221
|
+
};
|
222
|
+
|
223
|
+
Compiler.prototype.emitAssets = function(compilation, callback) {
|
224
|
+
var outputPath;
|
225
|
+
|
226
|
+
this.applyPluginsAsync("emit", compilation, function(err) {
|
227
|
+
if(err) return callback(err);
|
228
|
+
outputPath = compilation.getPath(this.outputPath);
|
229
|
+
this.outputFileSystem.mkdirp(outputPath, emitFiles.bind(this));
|
230
|
+
}.bind(this));
|
231
|
+
|
232
|
+
function emitFiles(err) {
|
233
|
+
if(err) return callback(err);
|
234
|
+
|
235
|
+
require("async").forEach(Object.keys(compilation.assets), function(file, callback) {
|
236
|
+
|
237
|
+
var targetFile = file;
|
238
|
+
var queryStringIdx = targetFile.indexOf("?");
|
239
|
+
if(queryStringIdx >= 0) {
|
240
|
+
targetFile = targetFile.substr(0, queryStringIdx);
|
241
|
+
}
|
242
|
+
|
243
|
+
if(targetFile.match(/\/|\\/)) {
|
244
|
+
var dir = path.dirname(targetFile);
|
245
|
+
this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut.bind(this));
|
246
|
+
} else writeOut.call(this);
|
247
|
+
|
248
|
+
function writeOut(err) {
|
249
|
+
if(err) return callback(err);
|
250
|
+
var targetPath = this.outputFileSystem.join(outputPath, targetFile);
|
251
|
+
var source = compilation.assets[file];
|
252
|
+
if(source.existsAt === targetPath) {
|
253
|
+
source.emitted = false;
|
254
|
+
return callback();
|
255
|
+
}
|
256
|
+
var content = source.source();
|
257
|
+
if(!Buffer.isBuffer(content))
|
258
|
+
content = new Buffer(content, "utf-8");
|
259
|
+
source.existsAt = targetPath;
|
260
|
+
source.emitted = true;
|
261
|
+
this.outputFileSystem.writeFile(targetPath, content, callback);
|
262
|
+
}
|
263
|
+
|
264
|
+
}.bind(this), function(err) {
|
265
|
+
if(err) return callback(err);
|
266
|
+
|
267
|
+
afterEmit.call(this);
|
268
|
+
}.bind(this));
|
269
|
+
}
|
270
|
+
|
271
|
+
function afterEmit() {
|
272
|
+
this.applyPluginsAsync("after-emit", compilation, function(err) {
|
273
|
+
if(err) return callback(err);
|
274
|
+
|
275
|
+
return callback();
|
276
|
+
});
|
277
|
+
}
|
278
|
+
|
279
|
+
};
|
280
|
+
|
281
|
+
Compiler.prototype.emitRecords = function emitRecords(callback) {
|
282
|
+
if(!this.recordsOutputPath) return callback();
|
283
|
+
var idx1 = this.recordsOutputPath.lastIndexOf("/");
|
284
|
+
var idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
285
|
+
var recordsOutputPathDirectory = null;
|
286
|
+
if(idx1 > idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
287
|
+
if(idx1 < idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
288
|
+
if(!recordsOutputPathDirectory) return writeFile.call(this);
|
289
|
+
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, function(err) {
|
290
|
+
if(err) return callback(err);
|
291
|
+
writeFile.call(this);
|
292
|
+
}.bind(this));
|
293
|
+
|
294
|
+
function writeFile() {
|
295
|
+
this.outputFileSystem.writeFile(this.recordsOutputPath, JSON.stringify(this.records, undefined, 2), callback);
|
296
|
+
}
|
297
|
+
};
|
298
|
+
|
299
|
+
Compiler.prototype.readRecords = function readRecords(callback) {
|
300
|
+
if(!this.recordsInputPath) {
|
301
|
+
this.records = {};
|
302
|
+
return callback();
|
303
|
+
}
|
304
|
+
this.inputFileSystem.stat(this.recordsInputPath, function(err) {
|
305
|
+
// It doesn't exist
|
306
|
+
// We can ignore this.
|
307
|
+
if(err) return callback();
|
308
|
+
|
309
|
+
this.inputFileSystem.readFile(this.recordsInputPath, function(err, content) {
|
310
|
+
if(err) return callback(err);
|
311
|
+
|
312
|
+
try {
|
313
|
+
this.records = JSON.parse(content);
|
314
|
+
} catch(e) {
|
315
|
+
e.message = "Cannot parse records: " + e.message;
|
316
|
+
return callback(e);
|
317
|
+
}
|
318
|
+
|
319
|
+
return callback();
|
320
|
+
}.bind(this));
|
321
|
+
}.bind(this));
|
322
|
+
};
|
323
|
+
|
324
|
+
Compiler.prototype.createChildCompiler = function(compilation, compilerName, outputOptions) {
|
325
|
+
var childCompiler = new Compiler();
|
326
|
+
for(var name in this._plugins) {
|
327
|
+
if(["make", "compile", "emit", "after-emit", "invalid", "done", "this-compilation"].indexOf(name) < 0)
|
328
|
+
childCompiler._plugins[name] = this._plugins[name].slice();
|
329
|
+
}
|
330
|
+
childCompiler.name = compilerName;
|
331
|
+
childCompiler.outputPath = this.outputPath;
|
332
|
+
childCompiler.inputFileSystem = this.inputFileSystem;
|
333
|
+
childCompiler.outputFileSystem = null;
|
334
|
+
childCompiler.resolvers = this.resolvers;
|
335
|
+
childCompiler.parser = this.parser;
|
336
|
+
childCompiler.fileTimestamps = this.fileTimestamps;
|
337
|
+
childCompiler.contextTimestamps = this.contextTimestamps;
|
338
|
+
if(!this.records[compilerName]) this.records[compilerName] = [];
|
339
|
+
this.records[compilerName].push(childCompiler.records = {});
|
340
|
+
childCompiler.options = Object.create(this.options);
|
341
|
+
childCompiler.options.output = Object.create(childCompiler.options.output);
|
342
|
+
for(name in outputOptions) {
|
343
|
+
childCompiler.options.output[name] = outputOptions[name];
|
344
|
+
}
|
345
|
+
childCompiler.parentCompilation = compilation;
|
346
|
+
return childCompiler;
|
347
|
+
};
|
348
|
+
|
349
|
+
Compiler.prototype.isChild = function() {
|
350
|
+
return !!this.parentCompilation;
|
351
|
+
};
|
352
|
+
|
353
|
+
Compiler.prototype.createCompilation = function() {
|
354
|
+
return new Compilation(this);
|
355
|
+
};
|
356
|
+
|
357
|
+
Compiler.prototype.newCompilation = function(params) {
|
358
|
+
var compilation = this.createCompilation();
|
359
|
+
compilation.fileTimestamps = this.fileTimestamps;
|
360
|
+
compilation.contextTimestamps = this.contextTimestamps;
|
361
|
+
compilation.name = this.name;
|
362
|
+
compilation.records = this.records;
|
363
|
+
this.applyPlugins("this-compilation", compilation, params);
|
364
|
+
this.applyPlugins("compilation", compilation, params);
|
365
|
+
return compilation;
|
366
|
+
};
|
367
|
+
|
368
|
+
Compiler.prototype.createNormalModuleFactory = function() {
|
369
|
+
var normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.parser, this.options.module || {});
|
370
|
+
this.applyPlugins("normal-module-factory", normalModuleFactory);
|
371
|
+
return normalModuleFactory;
|
372
|
+
};
|
373
|
+
|
374
|
+
Compiler.prototype.createContextModuleFactory = function() {
|
375
|
+
var contextModuleFactory = new ContextModuleFactory(this.resolvers, this.inputFileSystem);
|
376
|
+
this.applyPlugins("context-module-factory", contextModuleFactory);
|
377
|
+
return contextModuleFactory;
|
378
|
+
};
|
379
|
+
|
380
|
+
Compiler.prototype.newCompilationParams = function() {
|
381
|
+
var params = {
|
382
|
+
normalModuleFactory: this.createNormalModuleFactory(),
|
383
|
+
contextModuleFactory: this.createContextModuleFactory()
|
384
|
+
};
|
385
|
+
return params;
|
386
|
+
};
|
387
|
+
|
388
|
+
Compiler.prototype.compile = function(callback) {
|
389
|
+
var params = this.newCompilationParams();
|
390
|
+
this.applyPlugins("compile", params);
|
391
|
+
|
392
|
+
var compilation = this.newCompilation(params);
|
393
|
+
|
394
|
+
this.applyPluginsParallel("make", compilation, function(err) {
|
395
|
+
if(err) return callback(err);
|
396
|
+
|
397
|
+
compilation.seal(function(err) {
|
398
|
+
if(err) return callback(err);
|
399
|
+
|
400
|
+
this.applyPluginsAsync("after-compile", compilation, function(err) {
|
401
|
+
if(err) return callback(err);
|
402
|
+
|
403
|
+
return callback(null, compilation);
|
404
|
+
});
|
405
|
+
}.bind(this));
|
406
|
+
}.bind(this));
|
407
|
+
};
|