Skip to content

Commit 9a800d5

Browse files
committed
fixed buggy PRs for webpack.configs
fixes webpack#956 fixes webpack#964
1 parent 026170a commit 9a800d5

4 files changed

Lines changed: 60 additions & 68 deletions

File tree

bin/convert-argv.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,32 @@ module.exports = function(optimist, argv, convertOptions) {
2929

3030
var configPath, ext;
3131
if (argv.config) {
32-
configPath = argv.config;
32+
configPath = path.resolve(argv.config);
3333
ext = path.extname(configPath);
3434
} else {
35-
var found = Object.keys(interpret.extensions).some(function(extname) {
36-
ext = extname;
37-
configPath = path.resolve('webpack.config' + ext);
38-
return fs.existsSync(configPath);
39-
});
40-
41-
if (!found) {
42-
configPath = 'webpack.config.js';
43-
ext = '.js';
35+
var extensions = Object.keys(interpret.extensions);
36+
for(var i = 0; i < extensions.length; i++) {
37+
var webpackConfig = path.resolve('webpack.config' + extensions[i]);
38+
if(fs.existsSync(webpackConfig)) {
39+
ext = extensions[i];
40+
configPath = webpackConfig;
41+
break;
42+
}
4443
}
4544
}
4645

47-
var moduleName = interpret.extensions[ext];
48-
if (moduleName) {
49-
var compiler = require(moduleName);
50-
var register = interpret.register[moduleName];
51-
var config = interpret.configurations[moduleName];
52-
if (register) {
53-
register(compiler, config);
46+
if(configPath) {
47+
var moduleName = interpret.extensions[ext];
48+
if (moduleName) {
49+
var compiler = require(moduleName);
50+
var register = interpret.register[moduleName];
51+
var config = interpret.configurations[moduleName];
52+
if (register) {
53+
register(compiler, config);
54+
}
5455
}
56+
options = require(configPath);
5557
}
56-
options = require(configPath);
5758

5859
if(typeof options !== "object" || options === null) {
5960
console.log("Config did not export a object.");

test/browsertest/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ library1.on("exit", function(code) {
4141
bindOutput(main);
4242
}
4343
});
44-
// 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
44+
// 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
4545
var library2 = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo", "--colors", "--output-library-target", "umd", "--output-jsonp-function", "webpackJsonpLib2",
46-
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.js", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
46+
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.coffee", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
4747
bindOutput(library2);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
webpack = require("../../");
2+
module.exports =
3+
output:
4+
hashDigestLength: 5
5+
module:
6+
postLoaders: [
7+
{ test: /extra2?\.js/, loader: "raw!extra!val?cacheable" }
8+
]
9+
amd:
10+
fromOptions: true
11+
resolve:
12+
# cannot resolve should outside the outermost node_modules
13+
# so it is injected here
14+
alias:
15+
should: require.resolve "should"
16+
plugins: [
17+
new webpack.optimize.LimitChunkCountPlugin 2
18+
new webpack.DefinePlugin
19+
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
20+
CONST_UNDEFINED: undefined,
21+
CONST_NULL: null,
22+
CONST_TRUE: true,
23+
CONST_FALSE: false,
24+
CONST_FUNCTION: -> return "ok";
25+
CONST_NUMBER: 123,
26+
CONST_NUMBER_EXPR: "1*100+23",
27+
CONST_OBJECT: {
28+
A: 1,
29+
B: JSON.stringify("B"),
30+
C: -> return "C";
31+
}
32+
new webpack.ProvidePlugin
33+
s3: "submodule3"
34+
->
35+
this.plugin "normal-module-factory", (nmf) ->
36+
nmf.plugin "after-resolve", (data, callback) ->
37+
data.resource = data.resource.replace /extra\.js/, "extra2.js";
38+
callback null, data;
39+
]

test/browsertest/library2config.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)