mirror of https://github.com/webpack/webpack.git
Sorted out some MultiCompiler issues
This commit is contained in:
parent
d447e49276
commit
1e37053f7e
|
|
@ -10,28 +10,34 @@ function CachePlugin(cache) {
|
|||
module.exports = CachePlugin;
|
||||
|
||||
CachePlugin.prototype.apply = function(compiler) {
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.cache = this.cache;
|
||||
}.bind(this));
|
||||
compiler.plugin("run", function(compiler, callback) {
|
||||
if(!compiler._lastCompilationFileDependencies) return callback();
|
||||
var fs = compiler.inputFileSystem;
|
||||
fileTs = compiler.fileTimestamps = {};
|
||||
async.forEach(compiler._lastCompilationFileDependencies, function(file, callback) {
|
||||
fs.stat(file, function(err, stat) {
|
||||
if(err) {
|
||||
if(err.code === 'ENOENT') return callback();
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
fileTs[file] = stat.mtime || Infinity;
|
||||
callback();
|
||||
});
|
||||
}, callback);
|
||||
}.bind(this));
|
||||
compiler.plugin("after-compile", function(compilation, callback) {
|
||||
compilation.compiler._lastCompilationFileDependencies = compilation.fileDependencies;
|
||||
compilation.compiler._lastCompilationContextDependencies = compilation.contextDependencies;
|
||||
callback();
|
||||
}.bind(this));
|
||||
if(Array.isArray(compiler.compilers)) {
|
||||
compiler.compilers.forEach(function(c, idx) {
|
||||
c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
|
||||
}, this);
|
||||
} else {
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.cache = this.cache;
|
||||
}.bind(this));
|
||||
compiler.plugin("run", function(compiler, callback) {
|
||||
if(!compiler._lastCompilationFileDependencies) return callback();
|
||||
var fs = compiler.inputFileSystem;
|
||||
fileTs = compiler.fileTimestamps = {};
|
||||
async.forEach(compiler._lastCompilationFileDependencies, function(file, callback) {
|
||||
fs.stat(file, function(err, stat) {
|
||||
if(err) {
|
||||
if(err.code === 'ENOENT') return callback();
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
fileTs[file] = stat.mtime || Infinity;
|
||||
callback();
|
||||
});
|
||||
}, callback);
|
||||
}.bind(this));
|
||||
compiler.plugin("after-compile", function(compilation, callback) {
|
||||
compilation.compiler._lastCompilationFileDependencies = compilation.fileDependencies;
|
||||
compilation.compiler._lastCompilationContextDependencies = compilation.contextDependencies;
|
||||
callback();
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
|
@ -47,6 +47,19 @@ function MultiCompiler(compilers) {
|
|||
}
|
||||
delegateProperty.call(this, "outputFileSystem");
|
||||
delegateProperty.call(this, "inputFileSystem");
|
||||
|
||||
Object.defineProperty(this, "outputPath", {
|
||||
configurable: false,
|
||||
get: function() {
|
||||
var commonPath = compilers[0].outputPath;
|
||||
for(var i = 1; i < compilers.length; i++) {
|
||||
while(compilers[i].outputPath.indexOf(commonPath) !== 0 || commonPath.length <= 1) {
|
||||
commonPath = commonPath.replace(/[\/\\][^\/\\]*$/, "");
|
||||
}
|
||||
}
|
||||
return commonPath;
|
||||
}
|
||||
});
|
||||
|
||||
var doneCompilers = 0;
|
||||
var compilerStats = [];
|
||||
|
|
|
|||
|
|
@ -8,53 +8,69 @@ function ProgressPlugin(handler) {
|
|||
module.exports = ProgressPlugin;
|
||||
|
||||
ProgressPlugin.prototype.apply = function(compiler) {
|
||||
var lastModulesCount = 0;
|
||||
var moduleCount = 1;
|
||||
var doneModules = 0;
|
||||
var handler = this.handler;
|
||||
function update() {
|
||||
handler(0.1 + (doneModules / Math.max(lastModulesCount, moduleCount)) * 0.6, doneModules + "/" + moduleCount + " build modules");
|
||||
if(compiler.compilers) {
|
||||
var states = new Array(compiler.compilers.length);
|
||||
compiler.compilers.forEach(function(compiler, idx) {
|
||||
compiler.apply(new ProgressPlugin(function(p, msg) {
|
||||
states[idx] = [p, msg];
|
||||
handler(states.map(function(state) {
|
||||
return state && state[0] || 0;
|
||||
}).reduce(function(a, b) {
|
||||
return a + b;
|
||||
}) / states.length, states.map(function(state) {
|
||||
return state && state[1];
|
||||
}).filter(Boolean).join(" | "));
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
var lastModulesCount = 0;
|
||||
var moduleCount = 1;
|
||||
var doneModules = 0;
|
||||
function update() {
|
||||
handler(0.1 + (doneModules / Math.max(lastModulesCount, moduleCount)) * 0.6, doneModules + "/" + moduleCount + " build modules");
|
||||
}
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
if(compilation.compiler.isChild()) return;
|
||||
lastModulesCount = moduleCount;
|
||||
moduleCount = 0;
|
||||
doneModules = 0;
|
||||
handler(0, "compile");
|
||||
compilation.plugin("build-module", function(module) {
|
||||
moduleCount++;
|
||||
update();
|
||||
});
|
||||
compilation.plugin("succeed-module", function(module) {
|
||||
doneModules++;
|
||||
update();
|
||||
});
|
||||
compilation.plugin("optimize", function() {
|
||||
handler(0.73, "optimize");
|
||||
});
|
||||
compilation.plugin("before-hash", function() {
|
||||
handler(0.75, "hashing");
|
||||
});
|
||||
compilation.plugin("before-chunk-assets", function() {
|
||||
handler(0.76, "create chunk assets");
|
||||
});
|
||||
compilation.plugin("additional-chunk-assets", function() {
|
||||
handler(0.78, "additional chunk assets");
|
||||
});
|
||||
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
|
||||
handler(0.8, "optimize chunk assets");
|
||||
callback();
|
||||
});
|
||||
compilation.plugin("optimize-assets", function(assets, callback) {
|
||||
handler(0.9, "optimize assets");
|
||||
callback();
|
||||
});
|
||||
});
|
||||
compiler.plugin("emit", function(compilation, callback) {
|
||||
handler(0.95, "emit");
|
||||
callback();
|
||||
});
|
||||
compiler.plugin("done", function(stats) {
|
||||
handler(1, "");
|
||||
});
|
||||
}
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
if(compilation.compiler.isChild()) return;
|
||||
lastModulesCount = moduleCount;
|
||||
moduleCount = 0;
|
||||
doneModules = 0;
|
||||
handler(0, "compile");
|
||||
compilation.plugin("build-module", function(module) {
|
||||
moduleCount++;
|
||||
update();
|
||||
});
|
||||
compilation.plugin("succeed-module", function(module) {
|
||||
doneModules++;
|
||||
update();
|
||||
});
|
||||
compilation.plugin("optimize", function() {
|
||||
handler(0.73, "optimize");
|
||||
});
|
||||
compilation.plugin("before-hash", function() {
|
||||
handler(0.75, "hashing");
|
||||
});
|
||||
compilation.plugin("before-chunk-assets", function() {
|
||||
handler(0.76, "create chunk assets");
|
||||
});
|
||||
compilation.plugin("additional-chunk-assets", function() {
|
||||
handler(0.78, "additional chunk assets");
|
||||
});
|
||||
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
|
||||
handler(0.8, "optimize chunk assets");
|
||||
callback();
|
||||
});
|
||||
compilation.plugin("optimize-assets", function(assets, callback) {
|
||||
handler(0.9, "optimize assets");
|
||||
callback();
|
||||
});
|
||||
});
|
||||
compiler.plugin("emit", function(compilation, callback) {
|
||||
handler(0.95, "emit");
|
||||
callback();
|
||||
});
|
||||
compiler.plugin("done", function(stats) {
|
||||
handler(1, "");
|
||||
});
|
||||
};
|
||||
|
|
@ -27,12 +27,14 @@ describe("ConfigTestCases", function() {
|
|||
var testDirectory = path.join(casesPath, category.name, testName);
|
||||
var outputDirectory = path.join(__dirname, "js", "config", category.name, testName);
|
||||
var options = require(path.join(testDirectory, "webpack.config.js"));
|
||||
if(!options.context) options.context = testDirectory;
|
||||
if(!options.entry) options.entry = "./index.js";
|
||||
if(!options.target) options.target = "async-node";
|
||||
if(!options.output) options.output = {};
|
||||
if(!options.output.path) options.output.path = outputDirectory;
|
||||
if(!options.output.filename) options.output.filename = "bundle.js";
|
||||
[].concat(options).forEach(function(options, idx) {
|
||||
if(!options.context) options.context = testDirectory;
|
||||
if(!options.entry) options.entry = "./index.js";
|
||||
if(!options.target) options.target = "async-node";
|
||||
if(!options.output) options.output = {};
|
||||
if(!options.output.path) options.output.path = outputDirectory;
|
||||
if(!options.output.filename) options.output.filename = "bundle" + idx + ".js";
|
||||
});
|
||||
webpack(options, function(err, stats) {
|
||||
if(err) return done(err);
|
||||
var jsonStats = stats.toJson({
|
||||
|
|
@ -56,7 +58,8 @@ describe("ConfigTestCases", function() {
|
|||
return module.exports;
|
||||
} else return require(module);
|
||||
}
|
||||
_require("./bundle.js");
|
||||
for(var i = 0; i < [].concat(options).length; i++)
|
||||
_require("./bundle" + i + ".js");
|
||||
if(exportedTest === 0) return done(new Error("No tests exported by test case"));
|
||||
done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
it("should run a multi compiler", function() {
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
var path = require("path");
|
||||
var webpack = require("../../../../");
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
|
||||
}
|
||||
];
|
||||
Loading…
Reference in New Issue