1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | if (!module.parent) {
|
6 |
|
7 | const { register } = require('./lib/global');
|
8 |
|
9 | register();
|
10 | }
|
11 |
|
12 | const chalk = require('chalk');
|
13 | const debug = require('debug')('webpack-serve');
|
14 | const findUp = require('find-up');
|
15 | const meow = require('meow');
|
16 | const importLocal = require('import-local');
|
17 |
|
18 |
|
19 |
|
20 | if (importLocal(__filename)) {
|
21 | debug('Using local install of webpack-serve');
|
22 | return;
|
23 | }
|
24 |
|
25 | const serve = require('./');
|
26 |
|
27 | const cli = meow(chalk`
|
28 | {underline Usage}
|
29 | $ webpack-serve <config> [...options]
|
30 |
|
31 | {underline Options}
|
32 | --config The webpack config to serve. Alias for <config>.
|
33 | --content The path from which content will be served
|
34 | --dev An object containing options for webpack-dev-middleware
|
35 | --host The host the app should bind to
|
36 | --http2 Instruct the server to use HTTP2
|
37 | --https-cert Specify a cert to enable https. Must be paired with a key
|
38 | --https-key Specify a key to enable https. Must be paired with a cert
|
39 | --https-pass Specify a passphrase to enable https. Must be paired with a pfx file
|
40 | --https-pfx Specify a pfx file to enable https. Must be paired with a passphrase
|
41 | --log-level Limit all process console messages to a specific level and above
|
42 | {dim Levels: trace, debug, info, warn, error, silent}
|
43 | --log-time Instruct the logger for webpack-serve and dependencies to display a timestamp
|
44 | --no-hot Instruct the client not to apply Hot Module Replacement patches
|
45 | --no-reload Instruct middleware {italic not} to reload the page for build errors
|
46 | --open Instruct the app to open in the default browser
|
47 | --open-app The name of the app to open the app within
|
48 | --open-path The path with the app a browser should open to
|
49 | --port The port the app should listen on
|
50 | --version Display the webpack-serve version
|
51 |
|
52 | {underline Examples}
|
53 | $ webpack-serve --no-reload
|
54 | `);
|
55 |
|
56 | const flags = Object.assign({}, cli.flags);
|
57 |
|
58 | if (cli.input.length) {
|
59 | [flags.config] = cli.input;
|
60 | } else if (!flags.config) {
|
61 | const filePath = findUp.sync('webpack.config.js');
|
62 | flags.config = filePath;
|
63 | }
|
64 |
|
65 | if (!flags.config) {
|
66 | cli.showHelp(0);
|
67 | }
|
68 |
|
69 | serve({ flags });
|