let loaders emit warnings/errors, don't fail on entry module error
This commit is contained in:
parent
0cf8a98be6
commit
466ec90ffa
|
@ -477,7 +477,11 @@ You can also save this options object in a JSON file and use it with the shell c
|
|||
// "-web-loader", "-loader", ""]
|
||||
// postfixes for loader modules to try
|
||||
|
||||
loaders: [{test: /\.generator.js/, loader: "val"}],
|
||||
loaders: [{
|
||||
test: /\.generator\.js/,
|
||||
exclude: /\.no\.generator\.js/,
|
||||
loader: "val"
|
||||
}],
|
||||
// default: (defaults are also included if you define your own)
|
||||
// [{test: /\.coffee$/, loader: "coffee"},
|
||||
// {test: /\.json$/, loader: "json"},
|
||||
|
@ -485,7 +489,8 @@ You can also save this options object in a JSON file and use it with the shell c
|
|||
// {test: /\.css$/, loader: "style!css"},
|
||||
// {test: /\.less$/, loader: "style!css!val!less"}]
|
||||
// automatically use loaders if filename match RegExp
|
||||
// and no loader is specified
|
||||
// and no loader is specified.
|
||||
// you can pass a RegExp as string, or multiple RegExps/strings in an array
|
||||
|
||||
postprocess: {
|
||||
normal: [function(filename, callback) {
|
||||
|
|
|
@ -48,8 +48,9 @@ module.exports = function buildDeps(context, mainModule, options, callback) {
|
|||
// all other stuff is added recursivly
|
||||
addModule(depTree, context, mainModule, options, {type: "main"}, function(err, id) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
return;
|
||||
depTree.errors.push("Entry module failed!\n " + err +
|
||||
"\n @ " + mainModule);
|
||||
id = 0;
|
||||
}
|
||||
buildTree(id);
|
||||
});
|
||||
|
@ -216,16 +217,29 @@ function addModule(depTree, context, modu, options, reason, finalCallback) {
|
|||
context, filenameWithLoaders,
|
||||
preLoaders, loaders, postLoaders,
|
||||
filename,
|
||||
options, function(err, source, deps, dependencyInfo, profileBuild) {
|
||||
options, function(err, extraResults, source, deps) {
|
||||
|
||||
var dependencyInfo = extraResults && extraResults.dependencyInfo;
|
||||
if(dependencyInfo) modu.dependencies = dependencyInfo.files; // It my be also supplied if err is set.
|
||||
if(extraResults && extraResults.warnings && extraResults.warnings.length > 0) {
|
||||
extraResults.warnings.forEach(function(w) {
|
||||
depTree.warnings.push(w + "\n @ loader @ " + filenameWithLoaders);
|
||||
});
|
||||
modu.warnings = extraResults.warnings;
|
||||
}
|
||||
if(extraResults && extraResults.errors && extraResults.errors.length > 0) {
|
||||
extraResults.errors.forEach(function(e) {
|
||||
depTree.errors.push(e + "\n @ loader @ " + filenameWithLoaders);
|
||||
});
|
||||
modu.errors = extraResults.errors;
|
||||
}
|
||||
if(err) {
|
||||
modu.error = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(profile) {
|
||||
profile.buildModule = profileBuild;
|
||||
profile.buildModule = extraResults.profile;
|
||||
profile.buildModuleEnd = new Date();
|
||||
}
|
||||
if(dependencyInfo.cacheable && options.cache) {
|
||||
|
@ -243,11 +257,31 @@ function addModule(depTree, context, modu, options, reason, finalCallback) {
|
|||
}
|
||||
}
|
||||
|
||||
function asRegExp(test) {
|
||||
if(typeof test == "string") test = new RegExp(test);
|
||||
return test;
|
||||
}
|
||||
|
||||
function matchAny(test, str) {
|
||||
if(!test) return true;
|
||||
test = asRegExp(test);
|
||||
if(Array.isArray(test)) {
|
||||
return test.map(asRegExp).filter(function(regExp) {
|
||||
return regExp.test(str);
|
||||
}).length > 0;
|
||||
} else {
|
||||
return test.test(str);
|
||||
}
|
||||
}
|
||||
|
||||
function matchLoadersList(list) {
|
||||
return list.filter(function(item) {
|
||||
var regExp = item.test;
|
||||
if(typeof regExp == "string") regExp = new RegExp(regExp);
|
||||
return (regExp.test(filename));
|
||||
return matchAny(item.test, filename);
|
||||
}).filter(function(item) {
|
||||
return matchAny(item.include, filename);
|
||||
}).filter(function(item) {
|
||||
if(!item.exclude) return true;
|
||||
return !matchAny(item.exclude, filename);
|
||||
}).map(function(item) {
|
||||
return item.loader;
|
||||
}).join("!");
|
||||
|
|
|
@ -18,10 +18,17 @@ function buildModule(context, filenameWithLoaders,
|
|||
var dependencyInfo = {
|
||||
cacheable: true,
|
||||
files: [filename]
|
||||
};
|
||||
|
||||
var extraResults = {
|
||||
dependencyInfo: dependencyInfo,
|
||||
profile: profile,
|
||||
warnings: [],
|
||||
errors: []
|
||||
}
|
||||
|
||||
fs.readFile(filename, function(err, content) {
|
||||
if(err) return callback(err, null, null, dependencyInfo);
|
||||
if(err) return callback(err, extraResults);
|
||||
|
||||
profile && (profile.readEnd = new Date().getTime());
|
||||
|
||||
|
@ -29,23 +36,29 @@ function buildModule(context, filenameWithLoaders,
|
|||
loaders: loaders,
|
||||
preLoaders: preLoaders,
|
||||
postLoaders: postLoaders,
|
||||
loaderType: null
|
||||
loaderType: null,
|
||||
emitWarning: function(warning) {
|
||||
extraResults.warnings.push(warning);
|
||||
},
|
||||
emitError: function(error) {
|
||||
extraResults.errors.push(error);
|
||||
}
|
||||
};
|
||||
|
||||
loaderContext.loaderType = "preLoader";
|
||||
execLoaders(context, filenameWithLoaders, preLoaders, [filename], [content], loaderContext, dependencyInfo, options,
|
||||
function(err, result) {
|
||||
if(err) return callback(err, null, null, dependencyInfo);
|
||||
if(err) return callback(err, extraResults);
|
||||
profile && (profile.preLoadersEnd = new Date().getTime());
|
||||
loaderContext.loaderType = "loader";
|
||||
execLoaders(context, filenameWithLoaders, loaders, [filename], result, loaderContext, dependencyInfo, options,
|
||||
function(err, result) {
|
||||
if(err) return callback(err, null, null, dependencyInfo);
|
||||
if(err) return callback(err, extraResults);
|
||||
profile && (profile.loadersEnd = new Date().getTime());
|
||||
loaderContext.loaderType = "postLoader";
|
||||
execLoaders(context, filenameWithLoaders, postLoaders, [filename], result, loaderContext, dependencyInfo, options,
|
||||
function(err, result) {
|
||||
if(err) return callback(err, null, null, dependencyInfo);
|
||||
if(err) return callback(err, extraResults);
|
||||
profile && (profile.postLoadersEnd = new Date().getTime());
|
||||
return processJs(result)
|
||||
});
|
||||
|
@ -63,11 +76,11 @@ function buildModule(context, filenameWithLoaders,
|
|||
try {
|
||||
deps = parse(source, options.parse);
|
||||
} catch(e) {
|
||||
callback(new Error("File \"" + filenameWithLoaders + "\" parsing failed: " + e), null, null, dependencyInfo);
|
||||
callback(new Error("File \"" + filenameWithLoaders + "\" parsing failed: " + e), extraResults);
|
||||
return;
|
||||
}
|
||||
profile && (profile.end = new Date().getTime());
|
||||
return callback(null, source, deps, dependencyInfo, profile);
|
||||
return callback(null, extraResults, source, deps);
|
||||
}
|
||||
}
|
||||
module.exports = buildModule;
|
|
@ -39,9 +39,9 @@ process.on("message", function(msg) {
|
|||
buildModule(context, filenameWithLoaders,
|
||||
preLoaders, loaders, postLoaders,
|
||||
filename,
|
||||
options, function(err, source, deps, cacheInfo, profile) {
|
||||
options, function(err, extraResults, source, deps) {
|
||||
if(err) err = { message: err.message, stack: err.stack, _toString: err.toString() };
|
||||
process.send([id, err, source, deps, cacheInfo, profile]);
|
||||
process.send([id, err, extraResults, source, deps]);
|
||||
});
|
||||
break;
|
||||
case "resolve":
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "0.7.2",
|
||||
"version": "0.7.3",
|
||||
"author": "Tobias Koppers @sokra",
|
||||
"description": "Packs CommonJs/AMD Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in New Issue