Skip to content

Commit

Permalink
fixed buggy PRs for webpack.configs
Browse files Browse the repository at this point in the history
fixes #956
fixes #964
  • Loading branch information
sokra committed Apr 10, 2015
1 parent 026170a commit 9a800d5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 68 deletions.
37 changes: 19 additions & 18 deletions bin/convert-argv.js
Expand Up @@ -29,31 +29,32 @@ module.exports = function(optimist, argv, convertOptions) {

var configPath, ext;
if (argv.config) {
configPath = argv.config;
configPath = path.resolve(argv.config);
ext = path.extname(configPath);
} else {
var found = Object.keys(interpret.extensions).some(function(extname) {
ext = extname;
configPath = path.resolve('webpack.config' + ext);
return fs.existsSync(configPath);
});

if (!found) {
configPath = 'webpack.config.js';
ext = '.js';
var extensions = Object.keys(interpret.extensions);
for(var i = 0; i < extensions.length; i++) {
var webpackConfig = path.resolve('webpack.config' + extensions[i]);
if(fs.existsSync(webpackConfig)) {
ext = extensions[i];
configPath = webpackConfig;
break;
}
}
}

var moduleName = interpret.extensions[ext];
if (moduleName) {
var compiler = require(moduleName);
var register = interpret.register[moduleName];
var config = interpret.configurations[moduleName];
if (register) {
register(compiler, config);
if(configPath) {

This comment has been minimized.

Copy link
@akre54

akre54 Apr 10, 2015

Contributor

Cool thanks. I was trying to do this with the some above, but this seems like a better way of doing it.

var moduleName = interpret.extensions[ext];
if (moduleName) {
var compiler = require(moduleName);
var register = interpret.register[moduleName];
var config = interpret.configurations[moduleName];
if (register) {
register(compiler, config);
}
}
options = require(configPath);
}
options = require(configPath);

if(typeof options !== "object" || options === null) {
console.log("Config did not export a object.");
Expand Down
4 changes: 2 additions & 2 deletions test/browsertest/build.js
Expand Up @@ -41,7 +41,7 @@ library1.on("exit", function(code) {
bindOutput(main);
}
});
// node ../../bin/webpack --output-pathinfo --colors --output-library-target umd --output-jsonp-function webpackJsonpLib2 --output-public-path js/ --output-chunk-file [chunkhash].lib2.js --config library2config.js library2b library2 js/library2.js
// node ../../bin/webpack --output-pathinfo --colors --output-library-target umd --output-jsonp-function webpackJsonpLib2 --output-public-path js/ --output-chunk-file [chunkhash].lib2.js --config library2config.coffee library2b library2 js/library2.js
var library2 = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo", "--colors", "--output-library-target", "umd", "--output-jsonp-function", "webpackJsonpLib2",
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.js", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.coffee", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
bindOutput(library2);
39 changes: 39 additions & 0 deletions test/browsertest/library2config.coffee
@@ -0,0 +1,39 @@
webpack = require("../../");
module.exports =
output:
hashDigestLength: 5
module:
postLoaders: [
{ test: /extra2?\.js/, loader: "raw!extra!val?cacheable" }
]
amd:
fromOptions: true
resolve:
# cannot resolve should outside the outermost node_modules
# so it is injected here
alias:
should: require.resolve "should"
plugins: [
new webpack.optimize.LimitChunkCountPlugin 2
new webpack.DefinePlugin
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
CONST_UNDEFINED: undefined,
CONST_NULL: null,
CONST_TRUE: true,
CONST_FALSE: false,
CONST_FUNCTION: -> return "ok";
CONST_NUMBER: 123,
CONST_NUMBER_EXPR: "1*100+23",
CONST_OBJECT: {
A: 1,
B: JSON.stringify("B"),
C: -> return "C";
}
new webpack.ProvidePlugin
s3: "submodule3"
->
this.plugin "normal-module-factory", (nmf) ->
nmf.plugin "after-resolve", (data, callback) ->
data.resource = data.resource.replace /extra\.js/, "extra2.js";
callback null, data;
]
48 changes: 0 additions & 48 deletions test/browsertest/library2config.js

This file was deleted.

0 comments on commit 9a800d5

Please sign in to comment.