Skip to content

Commit a36916b

Browse files
committed
Support CoffeeScript configuration files
Simply add --coffee to the webpack invocation and it will read coffeescript configuration files if available or when specified. Alternatively, you can specify the config file with a .coffee suffix. Doesn't add `coffee-script` dependency to webpack install, that's up to the user. Fixes webpack#475
1 parent cd5252b commit a36916b

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎bin/config-optimist.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ module.exports = function(optimist) {
33

44
.boolean("help").alias("help", "h").alias("help", "?").describe("help")
55

6-
.string("config").describe("config")
6+
.string("config")
7+
.describe("config", "Read configuration from this module")
8+
.default("config", "webpack.config")
9+
10+
.boolean("coffee")
11+
.describe("coffee", "support CoffeeScript configuration files")
12+
.default("coffee", false)
713

814
.string("context").describe("context")
915

@@ -86,4 +92,4 @@ module.exports = function(optimist) {
8692
.boolean("d").describe("d", "shortcut for --debug --devtool sourcemap --output-pathinfo")
8793

8894
.boolean("p").describe("p", "shortcut for --optimize-minimize");
89-
};
95+
};

‎bin/convert-argv.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ module.exports = function(optimist, argv, convertOptions) {
2626
argv["optimize-occurence-order"] = true;
2727
}
2828

29-
if(argv.config) {
29+
if(argv.coffee || (argv.config && /\.coffee$/.test(argv.config))) {
30+
require('coffee-script/register');
31+
}
32+
33+
try {
3034
options = require(path.resolve(argv.config));
31-
} else {
32-
var configPath = path.resolve("webpack.config.js");
33-
if(fs.existsSync(configPath)) {
34-
options = require(configPath);
35-
}
35+
} catch (e) {
36+
console.log("Could not load configuration:\n", e);
37+
process.exit(-1);
3638
}
3739
if(typeof options !== "object" || options === null) {
3840
console.log("Config did not export a object.");

0 commit comments

Comments
 (0)