in with the new
This commit is contained in:
28
build-tools/loadersByExtension.js
Normal file
28
build-tools/loadersByExtension.js
Normal file
@@ -0,0 +1,28 @@
|
||||
function extsToRegExp(exts) {
|
||||
return new RegExp("\\.(" + exts.map(function(ext) {
|
||||
return ext.replace(/\./g, "\\.");
|
||||
}).join("|") + ")(\\?.*)?$");
|
||||
}
|
||||
|
||||
module.exports = function loadersByExtension(obj) {
|
||||
var loaders = [];
|
||||
Object.keys(obj).forEach(function(key) {
|
||||
var exts = key.split("|");
|
||||
var value = obj[key];
|
||||
var entry = {
|
||||
extensions: exts,
|
||||
test: extsToRegExp(exts)
|
||||
};
|
||||
if(Array.isArray(value)) {
|
||||
entry.loaders = value;
|
||||
} else if(typeof value === "string") {
|
||||
entry.loader = value;
|
||||
} else {
|
||||
Object.keys(value).forEach(function(valueKey) {
|
||||
entry[valueKey] = value[valueKey];
|
||||
});
|
||||
}
|
||||
loaders.push(entry);
|
||||
});
|
||||
return loaders;
|
||||
};
|
||||
Reference in New Issue
Block a user