- Notifications
You must be signed in to change notification settings - Fork128
webpack dev middleware
Note: The webpack-dev-middleware is for advanced users. Seewebpack-dev-server for a ready-to-use solution.
Note: For multiple webpackconfiguration seemiddware ordev-middleware
If you are looking for this middleware forkoa2 ecosystem loaded with HMR support see atkoa-webpack-middleware.
Thewebpack-dev-middleware is a small middleware for a connect-based middleware stack. It uses webpack to compile assets in-memory and serve them. When a compilation is running every request to the served webpack assets is blocked until we have a stable bundle.
You can use it in two modes:
- watch mode (default): The compiler recompiles on file change.
- lazy mode: The compiler compiles on every request to the entry point.
varwebpackDevMiddleware=require("webpack-dev-middleware");varwebpack=require("webpack");varcompiler=webpack({// configurationoutput:{path:'/'}});app.use(webpackDevMiddleware(compiler,{// options}));
Display no info to console (only warnings and errors)
Default:false
Display nothing to the console
Default:false
Switch into lazy mode.
Default:false
In lazy mode: Switch request should trigger the compilation.
In most cases this equals the webpack configuration optionoutput.filename
.
Delay the rebuilt after the first change. Value is a time in ms.
Default:300
true
: use polling
number: use polling with specified interval
Default:undefined
The path where to bind the middleware to the server.
In most cases this equals the webpack configuration optionoutput.publicPath
.
Add custom headers. i. e.{ "X-Custom-Header": "yes" }
Output options for the stats. Seenode.js API.
Manually invalidate the compilation. Useful if stuff of the compiler has changed.
A readable (in-memory) filesystem that can access the compiled data.
webpack 👍