$ npm install webpack-serve
A lean, modern, and flexible webpack development server
To begin, you'll need to install webpack-serve
:
$ npm install webpack-serve --save-dev
$ webpack-serve --help
Options
--config The webpack config to serve. Alias for <config>.
--content The path from which content will be served
--dev An object containing options for webpack-dev-middleware
--host The host the app should bind to
--http2 Instruct the server to use HTTP2
--https-cert Specify a cert to enable https. Must be paired with a key
--https-key Specify a key to enable https. Must be paired with a cert
--https-pass Specify a passphrase to enable https. Must be paired with a pfx file
--https-pfx Specify a pfx file to enable https. Must be paired with a passphrase
--log-level Limit all process console messages to a specific level and above
{dim Levels: trace, debug, info, warn, error, silent}
--log-time Instruct the logger for webpack-serve and dependencies to display a timestamp
--no-hot Instruct the client not to apply Hot Module Replacement patches
--no-reload Instruct middleware {italic not} to reload the page for build errors
--open Instruct the app to open in the default browser
--open-app The name of the app to open the app within
--open-path The path with the app a browser should open to
--port The port the app should listen on
--version Display the webpack-serve version
Examples
$ webpack-serve ./webpack.config.js --no-reload
Note: The CLI will use your local install of webpack-serve when available, even when run globally.
When using the API directly, the main entry point is the serve
function, which
is the default export of the module.
const serve = require('webpack-serve');
const config = require('./webpack.config.js');
serve({ config });
Returns an Object
containing:
close()
(Function) - Closes the server and its dependencies.on(eventName, fn)
(Function) - Binds a serve event to a function. See
Events.Type: Object
Options for initializing and controlling the server provided.
Type: webpack
Default: null
An instance of a webpack
compiler. A passed compiler's config will take
precedence over config
passed in options.
Type: Object
Default: {}
An object containing the configuration for creating a new webpack
compiler
instance.
Type: String|[String]
Default: []
The path, or array of paths, from which content will be served.
Type: Object
Default: { publicPath: '/' }
An object containing options for webpack-dev-middleware.
Type: Object
Default: 'localhost'
Sets the host that the WebSocket
server will listen on. If this doesn't match
the host of the server the module is used with, the module will not function
properly.
Type: Object
Default: {}
An object containing options for webpack-hot-client.
Type: Boolean
Default: false
If using Node v9 or greater, setting this option to true
will enable HTTP2
support.
Type: Object
Default: null
Passing this option will instruct webpack-serve
to create and serve the webpack
bundle and accompanying content through a secure server. The object should
contain properties matching:
{
key: fs.readFileSync('...key'), // Private keys in PEM format.
cert: fs.readFileSync('...cert'), // Cert chains in PEM format.
pfx: <String>, // PFX or PKCS12 encoded private key and certificate chain.
passphrase: <String> // A shared passphrase used for a single private key and/or a PFX.
}
See the Node documentation for more information.
Type: String
Default: info
Instructs webpack-serve
to output information to the console/terminal at levels
higher than the specified level. Valid levels:
[
'trace',
'debug',
'info',
'warn',
'error'
]
Type: Boolean
Default: false
Instruct webpack-serve
to prepend each line of log output with a [HH:mm:ss]
timestamp.
Type: Boolean|Object
Default: false
Instruct the module to open the served bundle in a browser. Accepts an Object
that matches:
{
app: <String>, // The proper name of the browser app to open.
path: <String> // The url path on the server to open.
}
Type: Number
Default: 8080
The port the server should listen on.
webpack-serve
emits select events which can be subscribed to. For example;
const serve = require('webpack-serve');
const config = require('./webpack.config.js');
serve({ config });
serve.on('listening', () => {
console.log('happy fun time');
});
Arguments: None
A core tenant of webpack-serve
is to stay lean in terms of feature set, and to
empower users with familiar and easily portable patterns to implement the same
features that those familiar with webpack-dev-server
have come to rely on. This
makes the module far easier to maintain, which ultimately benefits the user.
Luckily, flexibility baked into webpack-serve
makes it a snap to add-on features.
Listed below are some of the add-on patterns that can be found in
docs/addons:
We welcome your contributions! Please have a read of CONTRIBUTING.md for more information on how to get involved.
© 2010 - cnpmjs.org x YWFE | Home | YWFE