optimized err handling logic
This commit is contained in:
parent
e493348953
commit
4e6f902cab
|
|
@ -68,22 +68,6 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
|
|||
// Compile and return a promise
|
||||
return new Promise(function (resolve, reject) {
|
||||
childCompiler.runAsChild(function (err, entries, childCompilation) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
// Replace [hash] placeholders in filename
|
||||
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
|
||||
hash: childCompilation.hash,
|
||||
chunk: entries[0]
|
||||
});
|
||||
// Restore the parent compilation to the state like it
|
||||
// was before the child compilation
|
||||
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
|
||||
if (assetsBeforeCompilation[outputName] === undefined) {
|
||||
// If it wasn't there - delete it
|
||||
delete compilation.assets[outputName];
|
||||
}
|
||||
// Resolve / reject the promise
|
||||
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
|
||||
var errorDetails = childCompilation.errors.map(function (error) {
|
||||
|
|
@ -93,6 +77,18 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
|
|||
} else if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
// Replace [hash] placeholders in filename
|
||||
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
|
||||
hash: childCompilation.hash,
|
||||
chunk: entries[0]
|
||||
});
|
||||
// Restore the parent compilation to the state like it
|
||||
// was before the child compilation
|
||||
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
|
||||
if (assetsBeforeCompilation[outputName] === undefined) {
|
||||
// If it wasn't there - delete it
|
||||
delete compilation.assets[outputName];
|
||||
}
|
||||
resolve({
|
||||
// Hash of the template entry point
|
||||
hash: entries[0].hash,
|
||||
|
|
|
|||
Loading…
Reference in New Issue