webpack-serve
A lean, modern, and flexible webpack development server
Last updated 7 years ago by shellscape .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install webpack-serve 
SYNC missed versions from official npm registry.

npm node deps tests coverage chat

webpack-serve

A lean, modern, and flexible webpack development server

Getting Started

To begin, you'll need to install webpack-serve:

$ npm install webpack-serve --save-dev

CLI

$ 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.

API

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 });

serve([options])

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.

options

Type: Object

Options for initializing and controlling the server provided.

compiler

Type: webpack
Default: null

An instance of a webpack compiler. A passed compiler's config will take precedence over config passed in options.

config

Type: Object
Default: {}

An object containing the configuration for creating a new webpack compiler instance.

content

Type: String|[String]
Default: []

The path, or array of paths, from which content will be served.

dev

Type: Object
Default: { publicPath: '/' }

An object containing options for webpack-dev-middleware.

host

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.

hot

Type: Object
Default: {}

An object containing options for webpack-hot-client.

http2

Type: Boolean
Default: false

If using Node v9 or greater, setting this option to true will enable HTTP2 support.

https

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.

logLevel

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'
]
logTime

Type: Boolean
Default: false

Instruct webpack-serve to prepend each line of log output with a [HH:mm:ss] timestamp.

open

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.
}
port

Type: Number
Default: 8080

The port the server should listen on.

Events

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');
});

listening

Arguments: None

Add-on Features

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:

Contributing

We welcome your contributions! Please have a read of CONTRIBUTING.md for more information on how to get involved.

License

MIT

Current Tags

  • 3.0.0-beta.1                                ...           beta (6 years ago)
  • 4.0.0                                ...           latest (4 years ago)
  • 1.0.0-beta.1                                ...           next (7 years ago)

35 Versions

  • 4.0.0                                ...           4 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 3.0.0-beta.3                                ...           6 years ago
  • 3.0.0-beta.2                                ...           6 years ago
  • 3.0.0-beta.1                                ...           6 years ago
  • 2.0.3                                ...           6 years ago
  • 2.0.2                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 2.0.0-beta.6                                ...           6 years ago
  • 2.0.0-beta.5                                ...           6 years ago
  • 2.0.0-beta.4                                ...           6 years ago
  • 2.0.0-beta.3                                ...           6 years ago
  • 2.0.0-beta.2                                ...           6 years ago
  • 2.0.0-beta.1                                ...           7 years ago
  • 1.0.4                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.3.2                                ...           7 years ago
  • 0.3.1                                ...           7 years ago
  • 0.3.0                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.5                                ...           7 years ago
  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 1.0.0-beta.1                                ...           7 years ago
  • 0.0.0                                ...           9 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (19)
Dev Dependencies (16)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE