1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var path = require("path");
|
4 | var commander = require("commander");
|
5 | var compile_1 = require("./webpack/compile");
|
6 | var devServer_1 = require("./webpack/devServer");
|
7 | function cli(args) {
|
8 | var program = new commander.Command();
|
9 | program.description('See help for specific commands using [command] --help');
|
10 | program
|
11 | .command('compile')
|
12 | .description('Compile webpack assets')
|
13 | .option('-c, --config-file [config]', 'Path to webpack.config.js', 'webpack.config.js')
|
14 | .option('-s, --super-speed', 'Faster compilation using transpiled sourcemaps (eval)')
|
15 | .option('-v, --verbose', 'Verbose output')
|
16 | .action(function (_a) {
|
17 | var configFile = _a.configFile, superSpeed = _a.superSpeed, verbose = _a.verbose;
|
18 | var config = readConfig(configFile, superSpeed);
|
19 | return compile_1.default(config, { verbose: verbose });
|
20 | });
|
21 | program
|
22 | .command('dev')
|
23 | .description('Run the webpack dev server')
|
24 | .option('-c, --config-file [config]', 'Path to webpack.config.js', 'webpack.config.js')
|
25 | .option('-h, --hot', 'Hot module reload')
|
26 | .option('-l, --lazy', 'Lazy bundle compilation')
|
27 | .option('-s, --super-speed', 'Faster compilation using transpiled sourcemaps (eval)')
|
28 | .option('-v, --verbose', 'Verbose output')
|
29 | .option('--hot-host [host]', 'Set a custom HMR host')
|
30 | .action(function (_a) {
|
31 | var configFile = _a.configFile, hot = _a.hot, hotHost = _a.hotHost, lazy = _a.lazy, superSpeed = _a.superSpeed, verbose = _a.verbose;
|
32 | var webpackConfig = readConfig(configFile, superSpeed);
|
33 | return devServer_1.default(webpackConfig, { hot: hot, hotHost: hotHost, lazy: lazy, verbose: verbose });
|
34 | });
|
35 | if (!args.slice(2).length) {
|
36 | program.outputHelp();
|
37 | }
|
38 | else {
|
39 | program.parse(args);
|
40 | }
|
41 | }
|
42 | exports.default = cli;
|
43 | function readConfig(configPath, superSpeed) {
|
44 |
|
45 | var config = require(path.resolve(process.cwd(), configPath));
|
46 | if (superSpeed && config.devtool) {
|
47 | config.devtool = 'eval';
|
48 | }
|
49 | return config;
|
50 | }
|