Socket
Book a DemoInstallSign in
Socket

serve-webpack

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-webpack

A simple and fast webpack development server with HMR support

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

serve-webpack

A simple and fast webpack development server with HMR support

npm install -D serve-webpack
yarn add -D serve-webpack

Usage

The serve-webpack module is intended to be used as a local development server, that automatically compiles a Webpack configuration in watch-mode, and serves the output directory as static files over HTTP, using serve-handler. Additionally, a Websocket server is opened for HMR support, and a client-side script injected along with Webpack's HotModuleReplacementPlugin.

serve-webpack offers cli and node API support:

cli usage:

npx serve-webpack --require ts-node/register --config webpack.config.ts

node usage:

const serveWebpack = require('serve-webpack')
serveWebpack({ require: 'ts-node/register', config: 'webpack.config.ts' })

Configuration

Cli options

--require, -r

type: string (supports multiple)

Require a module before requiring the Webpack configuration. Useful for registering ts-node or babel, for example.

--config, -c

type: string

Path to the Webpack configuration, relative to process.cwd(). Supports a single configuration exported via module.exports either in object or function form. In case of an array, only the first is used.

--hot, -h

type: boolean
default: true

Enable or disable the Websocket server and other HMR additions. Enabled by default.

--env, -e

type: object (supports multiple)

Additional environment variables passed to the Webpack configurations that export a function. The function's argument will be an env object. For example, the following configuration

serve-webpack --env.NODE_ENV=local --env.production --env.test=false

will result in

// webpack.config.js
module.exports = (env) => {
  console.log(env.NODE_ENV) // "local"
  console.log(env.production) // true
  console.log(env.test) // false
}

Webpack configuration key

serve-webpack supports its custom key serve?: Object in the supplied Webpack configuration. Because this makes the configuration invalid, the key is deleted after parsing and before passing the rest to the Webpack compiler. Typescript type augmentations are available.

Options

keydescriptiontypedefault
protocolThe protocol of the dev server`http:https:`
hostThe hostname of the dev serverstringlocalhost
portThe port of the dev servernumber3000
socketPathThe path of the websocketstring/__socket
pathThe fs path from where serve-handler serves filesstringWebpack's output.path, eg. /public
pathThe url path where serve-handler bindsstringWebpack's output.publicPath, eg. /

The serve key also supports all serve-handler options, that are passed directly to it. All requests except for the socketPath are passed to the handler.

Keywords

dev-server

FAQs

Package last updated on 30 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.