Automatically pull in webpack.config files written in compile-to-js langs using interpret.extensions

This commit is contained in:
Adam Krebs 2015-04-08 08:26:06 -04:00
parent 1f74f58273
commit 2875e402d7
1 changed files with 20 additions and 15 deletions

View File

@ -27,10 +27,20 @@ module.exports = function(optimist, argv, convertOptions) {
argv["optimize-occurence-order"] = true;
}
var configPath, extname;
if (argv.config) {
var ext = path.extname(argv.config);
if (Object.keys(require.extensions).indexOf(ext) === -1) {
var moduleName = interpret.extensions[ext];
configPath = argv.config;
extname = path.extname(configPath);
} else {
Object.keys(interpret.extensions).some(function(ext) {
extname = ext;
configPath = path.resolve('webpack.config' + ext);
return fs.existsSync(configPath);
});
}
var moduleName = interpret.extensions[extname];
if (moduleName) {
var compiler = require(moduleName);
var register = interpret.register[moduleName];
var config = interpret.configurations[moduleName];
@ -38,13 +48,8 @@ module.exports = function(optimist, argv, convertOptions) {
register(compiler, config);
}
}
options = require(path.resolve(argv.config));
} else {
var configPath = path.resolve("webpack.config.js");
if(fs.existsSync(configPath)) {
options = require(configPath);
}
}
if(typeof options !== "object" || options === null) {
console.log("Config did not export a object.");
process.exit(-1);