separable loaders as opt-in feature, fixes #16
in future separable loaders may run in a sperate process for performance reasons
This commit is contained in:
parent
4c84defbb6
commit
c912c0134b
|
@ -409,6 +409,7 @@ You can also save this options object in a JSON file and use it with the shell c
|
|||
// "module" (module, filename) before a module is loaded
|
||||
// "context" (module, dirname) before a context is loaded
|
||||
// "dependency" (filename) before a dependency is loaded
|
||||
// "static-dependency"(filename) after a dependency is flagged as not recompile-able
|
||||
// "loader" (filename) before a loader is required
|
||||
// -- events for progress --
|
||||
// "task" (name?) start of a task
|
||||
|
|
|
@ -30,15 +30,21 @@ module.exports = function(context, request, loaders, filenames, contents, cacheE
|
|||
var loaderFilename = require.resolve(name);
|
||||
options.events.emit("loader", loaderFilename);
|
||||
|
||||
// require loader in fresh context
|
||||
var oldCache = {};
|
||||
for(var entry in require.cache) {
|
||||
oldCache[entry] = require.cache[entry];
|
||||
delete require.cache[entry];
|
||||
}
|
||||
var loader = require(loaderFilename);
|
||||
for(var entry in oldCache) {
|
||||
require.cache[entry] = oldCache[entry];
|
||||
|
||||
if(loader.separable) {
|
||||
// require loader in fresh context
|
||||
var oldCache = {};
|
||||
for(var entry in require.cache) {
|
||||
oldCache[entry] = require.cache[entry];
|
||||
delete require.cache[entry];
|
||||
}
|
||||
loader = require(loaderFilename);
|
||||
for(var entry in oldCache) {
|
||||
require.cache[entry] = oldCache[entry];
|
||||
}
|
||||
} else {
|
||||
options.events.emit("static-dependency", loaderFilename);
|
||||
}
|
||||
|
||||
loaderFunctions.push(loader);
|
||||
|
|
|
@ -165,6 +165,7 @@ module.exports = function(context, moduleName, options, callback) {
|
|||
var isRunning = true;
|
||||
var isWaiting = false;
|
||||
var runAgain = false;
|
||||
var staticChanges = [];
|
||||
|
||||
// Start the timeout again
|
||||
function startAgain() {
|
||||
|
@ -179,6 +180,11 @@ module.exports = function(context, moduleName, options, callback) {
|
|||
});
|
||||
watchers.length = 0;
|
||||
|
||||
if(staticChanges.length > 0)
|
||||
return callback(new Error(
|
||||
"Files (" + staticChanges.join(", ") +
|
||||
") changed. Webpack cannot recompile in this watch step."));
|
||||
|
||||
runAgain = false;
|
||||
isRunning = true;
|
||||
isWaiting = false;
|
||||
|
@ -229,6 +235,16 @@ module.exports = function(context, moduleName, options, callback) {
|
|||
}));
|
||||
});
|
||||
|
||||
// on before a static dependency is read
|
||||
options.events.on("static-dependency", function(filename) {
|
||||
if(!filename) return;
|
||||
watchers.push(fs.watch(filename, function() {
|
||||
if(staticChanges.indexOf(filename) == -1)
|
||||
staticChanges.push(filename);
|
||||
change();
|
||||
}));
|
||||
});
|
||||
|
||||
// on user defines the bundle as invalid
|
||||
options.events.on("invalid", function() {
|
||||
change();
|
||||
|
|
|
@ -39,5 +39,5 @@ libary1.on("exit", function(code) {
|
|||
}
|
||||
});
|
||||
var libary2 = cp.spawn("node", join(["../../bin/webpack.js", "--colors", "--libary", "libary2",
|
||||
"--script-src-prefix", "js/", "--options", "libary2config.js", "node_modules/libary2", "js/libary2.js"], extraArgs));
|
||||
"--script-src-prefix", "js/", "--options", "libary2config.js", "node_modules/libary2", "js/libary2.js"], extraArgsNoWatch));
|
||||
bindOutput(libary2);
|
||||
|
|
Loading…
Reference in New Issue