Skip to content

Commit 2e5a5f9

Browse files
committed
more pretty CLI options, added --verbose option
1 parent 3c885d9 commit 2e5a5f9

10 files changed

Lines changed: 448 additions & 75 deletions

bin/config-optimist.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ module.exports = function(optimist) {
99
.string("module-bind-post").describe("module-bind-post")
1010
.string("module-bind-pre").describe("module-bind-pre")
1111
.string("output-path").describe("output-path", "The output path for compilation assets")
12-
.string("output-file").describe("output-file", "The output filename of the bundle")
13-
.string("output-chunk-file").describe("output-chunk-file", "The output filename for additional chunks")
14-
.string("output-source-map-file").describe("output-source-map-file", "The output filename for the SourceMap")
12+
.string("output-filename").describe("output-filename", "The output filename of the bundle")
13+
.string("output-chunk-filename").describe("output-chunk-filename", "The output filename for additional chunks")
14+
.string("output-source-map-filename").describe("output-source-map-filename", "The output filename for the SourceMap")
1515
.string("output-public-path").describe("output-public-path", "The public path for the assets")
1616
.string("output-jsonp-function").describe("output-jsonp-function", "The name of the jsonp function used for chunk loading")
1717
.boolean("output-pathinfo").describe("output-pathinfo", "Include a comment with the request for every dependency")

bin/config-yargs.js

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
var CONFIG_GROUP = "Config options:";
2+
var BASIC_GROUP = "Basic options:";
3+
var MODULE_GROUP = "Module options:";
4+
var OUTPUT_GROUP = "Output options:";
5+
var ADVANCED_GROUP = "Advanced options:";
6+
var RESOLVE_GROUP = "Resolving options:";
7+
var OPTIMIZE_GROUP = "Optimizing options:";
8+
9+
module.exports = function(yargs) {
10+
yargs
11+
.help("help")
12+
.alias("help", "h", "?")
13+
.options({
14+
"config": {
15+
type: "string",
16+
describe: "Path to the config file",
17+
group: CONFIG_GROUP,
18+
defaultDescription: "webpack.config.js or webpackfile.js",
19+
requiresArg: true
20+
},
21+
"env": {
22+
describe: "Enviroment passed to the config, when it is a function",
23+
group: CONFIG_GROUP
24+
},
25+
"context": {
26+
type: "string",
27+
describe: "The root directory for resolving entry point and stats",
28+
group: BASIC_GROUP,
29+
defaultDescription: "The current directory",
30+
requiresArg: true
31+
},
32+
"entry": {
33+
type: "string",
34+
describe: "The entry point",
35+
group: BASIC_GROUP,
36+
requiresArg: true
37+
},
38+
"module-bind": {
39+
type: "string",
40+
describe: "Bind an extension to a loader",
41+
group: MODULE_GROUP,
42+
requiresArg: true
43+
},
44+
"module-bind-post": {
45+
type: "string",
46+
describe: "",
47+
group: MODULE_GROUP,
48+
requiresArg: true
49+
},
50+
"module-bind-pre": {
51+
type: "string",
52+
describe: "",
53+
group: MODULE_GROUP,
54+
requiresArg: true
55+
},
56+
"output-path": {
57+
type: "string",
58+
describe: "The output path for compilation assets",
59+
group: OUTPUT_GROUP,
60+
defaultDescription: "The current directory",
61+
requiresArg: true
62+
},
63+
"output-filename": {
64+
type: "string",
65+
describe: "The output filename of the bundle",
66+
group: OUTPUT_GROUP,
67+
defaultDescription: "[name].js",
68+
requiresArg: true
69+
},
70+
"output-chunk-filename": {
71+
type: "string",
72+
describe: "The output filename for additional chunks",
73+
group: OUTPUT_GROUP,
74+
defaultDescription: "filename with [id] instead of [name] or [id] prefixed",
75+
requiresArg: true
76+
},
77+
"output-source-map-filename": {
78+
type: "string",
79+
describe: "The output filename for the SourceMap",
80+
group: OUTPUT_GROUP,
81+
requiresArg: true
82+
},
83+
"output-public-path": {
84+
type: "string",
85+
describe: "The public path for the assets",
86+
group: OUTPUT_GROUP,
87+
requiresArg: true
88+
},
89+
"output-jsonp-function": {
90+
type: "string",
91+
describe: "The name of the jsonp function used for chunk loading",
92+
group: OUTPUT_GROUP,
93+
requiresArg: true
94+
},
95+
"output-pathinfo": {
96+
type: "boolean",
97+
describe: "Include a comment with the request for every dependency (require, import, etc.)",
98+
group: OUTPUT_GROUP
99+
},
100+
"output-library": {
101+
type: "string",
102+
describe: "Expose the exports of the entry point as library",
103+
group: OUTPUT_GROUP,
104+
requiresArg: true
105+
},
106+
"output-library-target": {
107+
type: "string",
108+
describe: "The type for exposing the exports of the entry point as library",
109+
group: OUTPUT_GROUP,
110+
requiresArg: true
111+
},
112+
"records-input-path": {
113+
type: "string",
114+
describe: "Path to the records file (reading)",
115+
group: ADVANCED_GROUP,
116+
requiresArg: true
117+
},
118+
"records-output-path": {
119+
type: "string",
120+
describe: "Path to the records file (writing)",
121+
group: ADVANCED_GROUP,
122+
requiresArg: true
123+
},
124+
"records-path": {
125+
type: "string",
126+
describe: "Path to the records file",
127+
group: ADVANCED_GROUP,
128+
requiresArg: true
129+
},
130+
"define": {
131+
type: "string",
132+
describe: "Define any free var in the bundle",
133+
group: ADVANCED_GROUP,
134+
requiresArg: true
135+
},
136+
"target": {
137+
type: "string",
138+
describe: "The targeted execution enviroment",
139+
group: ADVANCED_GROUP,
140+
requiresArg: true
141+
},
142+
"cache": {
143+
type: "boolean",
144+
describe: "Enable in memory caching",
145+
group: ADVANCED_GROUP,
146+
defaultDescription: "It's enabled by default when watching"
147+
},
148+
"watch": {
149+
type: "boolean",
150+
alias: "w",
151+
describe: "Watch the filesystem for changes",
152+
group: BASIC_GROUP
153+
},
154+
"watch-stdin": {
155+
type: "boolean",
156+
alias: "stdin",
157+
describe: "Exit the process when stdin is closed",
158+
group: ADVANCED_GROUP
159+
},
160+
"watch-aggregate-timeout": {
161+
describe: "Timeout for gathering changes while watching",
162+
group: ADVANCED_GROUP,
163+
requiresArg: true
164+
},
165+
"watch-poll": {
166+
type: "boolean",
167+
describe: "The polling intervall for watching (also enable polling)",
168+
group: ADVANCED_GROUP
169+
},
170+
"hot": {
171+
type: "boolean",
172+
describe: "Enables Hot Module Replacement",
173+
group: ADVANCED_GROUP
174+
},
175+
"debug": {
176+
type: "boolean",
177+
describe: "Switch loaders to debug mode",
178+
group: BASIC_GROUP
179+
},
180+
"devtool": {
181+
type: "string",
182+
describe: "Enable devtool for better debugging experience (Example: --devtool eval-cheap-module-source-map)",
183+
group: BASIC_GROUP,
184+
requiresArg: true
185+
},
186+
"progress": {
187+
type: "boolean",
188+
describe: "Print compilation progress in percentage",
189+
group: BASIC_GROUP
190+
},
191+
"resolve-alias": {
192+
type: "string",
193+
describe: "Setup a module alias for resolving (Example: jquery-plugin=jquery.plugin)",
194+
group: RESOLVE_GROUP,
195+
requiresArg: true
196+
},
197+
"resolve-loader-alias": {
198+
type: "string",
199+
describe: "Setup a loader alias for resolving",
200+
group: RESOLVE_GROUP,
201+
requiresArg: true
202+
},
203+
"optimize-max-chunks": {
204+
describe: "Try to keep the chunk count below a limit",
205+
group: OPTIMIZE_GROUP,
206+
requiresArg: true
207+
},
208+
"optimize-min-chunk-size": {
209+
describe: "Try to keep the chunk size above a limit",
210+
group: OPTIMIZE_GROUP,
211+
requiresArg: true
212+
},
213+
"optimize-minimize": {
214+
type: "boolean",
215+
describe: "Minimize javascript and switches loaders to minimizing",
216+
group: OPTIMIZE_GROUP
217+
},
218+
"optimize-dedupe": {
219+
type: "boolean",
220+
describe: "Optimize duplicate module sources in the bundle",
221+
group: OPTIMIZE_GROUP
222+
},
223+
"prefetch": {
224+
type: "string",
225+
describe: "Prefetch this request (Example: --prefetch ./file.js)",
226+
group: ADVANCED_GROUP,
227+
requiresArg: true
228+
},
229+
"provide": {
230+
type: "string",
231+
describe: "Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
232+
group: ADVANCED_GROUP,
233+
requiresArg: true
234+
},
235+
"labeled-modules": {
236+
type: "boolean",
237+
describe: "Enables labeled modules",
238+
group: ADVANCED_GROUP
239+
},
240+
"plugin": {
241+
type: "string",
242+
describe: "Load this plugin",
243+
group: ADVANCED_GROUP,
244+
requiresArg: true
245+
},
246+
"bail": {
247+
type: "boolean",
248+
describe: "Abort the compilation on first error",
249+
group: ADVANCED_GROUP
250+
},
251+
"profile": {
252+
type: "boolean",
253+
describe: "Profile the compilation and include information in stats",
254+
group: ADVANCED_GROUP
255+
},
256+
"d": {
257+
type: "boolean",
258+
describe: "shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
259+
group: BASIC_GROUP
260+
},
261+
"p": {
262+
type: "boolean",
263+
describe: "shortcut for --optimize-minimize --define process.env.NODE_ENV=\"production\"",
264+
group: BASIC_GROUP
265+
}
266+
}).strict();
267+
};

bin/convert-argv.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require("fs");
33
fs.existsSync = fs.existsSync || path.existsSync;
44
var resolve = require("enhanced-resolve");
55
var interpret = require("interpret");
6+
var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
67

78
module.exports = function(optimist, argv, convertOptions) {
89

@@ -100,7 +101,7 @@ module.exports = function(optimist, argv, convertOptions) {
100101

101102
function processConfiguredOptions(options) {
102103
if(typeof options !== "object" || options === null) {
103-
console.log("Config did not export an object or a function returning an object.");
104+
console.error("Config did not export an object or a function returning an object.");
104105
process.exit(-1); // eslint-disable-line
105106
}
106107

@@ -154,6 +155,8 @@ module.exports = function(optimist, argv, convertOptions) {
154155
}
155156

156157
function processOptions(options) {
158+
new WebpackOptionsDefaulter().process(options);
159+
157160
function ifArg(name, fn, init, finalize) {
158161
if(Array.isArray(argv[name])) {
159162
if(init) {
@@ -310,12 +313,12 @@ module.exports = function(optimist, argv, convertOptions) {
310313
options.output.filename = value;
311314
});
312315

313-
ifArg("output-chunk-file", function(value) {
316+
ifArg("output-chunk-filename", function(value) {
314317
ensureObject(options, "output");
315318
options.output.chunkFilename = value;
316319
});
317320

318-
ifArg("output-source-map-file", function(value) {
321+
ifArg("output-source-map-filename", function(value) {
319322
ensureObject(options, "output");
320323
options.output.sourceMapFilename = value;
321324
});
@@ -473,10 +476,11 @@ module.exports = function(optimist, argv, convertOptions) {
473476
options.output.path = path.dirname(options.output.filename);
474477
options.output.filename = path.basename(options.output.filename);
475478
} else if(configFileLoaded) {
476-
throw new Error("'output.filename' is required, either in config file or as --output-file");
479+
throw new Error("'output.filename' is required, either in config file or as --output-filename");
477480
} else {
478-
optimist.showHelp();
479-
console.error("Output filename not configured.");
481+
console.error("No configuration file found and no output filename configured via CLI option.");
482+
console.error("A configuration file could be named 'webpack.config.js' in the current directory.");
483+
console.error("Use --help to display the CLI options.");
480484
process.exit(-1); // eslint-disable-line
481485
}
482486
}
@@ -514,5 +518,17 @@ module.exports = function(optimist, argv, convertOptions) {
514518
}
515519
});
516520
}
521+
522+
if(!options.entry) {
523+
if(configPath) {
524+
console.error("Configuration file found but no entry configured.");
525+
} else {
526+
console.error("No configuration file found and no entry configured via CLI option.");
527+
console.error("When using the CLI you need to provide at least two arguments: entry and output.");
528+
console.error("A configuration file could be named 'webpack.config.js' in the current directory.");
529+
}
530+
console.error("Use --help to display the CLI options.");
531+
process.exit(-1); // eslint-disable-line
532+
}
517533
}
518534
};

0 commit comments

Comments
 (0)