UNPKG

2.45 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5if (!module.parent) {
6 // eslint-disable-next-line global-require
7 const { register } = require('./lib/global');
8
9 register();
10}
11
12const chalk = require('chalk');
13const debug = require('debug')('webpack-serve');
14const findUp = require('find-up');
15const meow = require('meow');
16const importLocal = require('import-local'); // eslint-disable-line import/order
17
18// Prefer the local installation of webpack-serve
19/* istanbul ignore if */
20if (importLocal(__filename)) {
21 debug('Using local install of webpack-serve');
22 return;
23}
24
25const serve = require('./');
26
27const 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
56const flags = Object.assign({}, cli.flags);
57
58if (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
65if (!flags.config) {
66 cli.showHelp(0);
67}
68
69serve({ flags });