Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

WARNING STATEMENT: This module is now considered legacy and should be used with newer webpack 3.x versions with caution due to possible bugs. Reconsider please to use webpack-dev-middleware instead. If you stillt want to use features like custom file system and bundle specific headers please consider to open new PR to the original middleware repo.


npm David David GitHub tag
Module API | Configuration | Miscellaneous | Credits | License

Server middleware that manages your webpack compilation easily.
Complete overhaul of the official webpack-dev-middleware version powered by a support of multiple webpack configurations and some handy features leveraging basic functionality.

$ npm i --no-optional webpack-middware
$ npm i --no-optional hinell/webpack-middware # latest version
    , Middware  = require('webpack-middware')
    , app       = require('express')();
      app.use((middware = new Middware({
    //  webpack compiler is REQUIRED (except when you have passed it early by first argument)
        compiler : new Webpack({ entry: ... , output: , plugins: [...] }), 
        publicPath :'/public' // [default - '/'] 
      , headers : {// headers to be send along with script bundle
        , 'Cache-control': 'max-age=0'  // common header to be sent with every bundle response
        , files :{ // bundle specific headers
            // headers to be sent for 'vendor' bundle request
            'vendor': { 'Cache-control': 'max-age=3600'}
      , fs    : new require('memory-fs') // specify in-memory or local file system [default - in memory]
      , watch : {}  // configure watch settings [see webpack watch settings]
       // ⚠ don't forget to provide the middleware callback to the .use()!
      // Miscellaneous
      middware.watching              // access watching, undefined in lazy mode (lazy option is specified)
      middware.watching.invalidate() // invalidate bundle
      middware.fs                    // file system access


var   middware = new Middware(compiler[, config]) // middware takes webpack compiler and optional config
var   middware = new Middware(config) // the compiler is provided by config property { compiler }

      middware.middleware // is of type of (req,res,next) server request listener (middleware)


.compiler - webpack compiler instance, this option is required
.fs - files system where compiled files are kept, by default it is equal to the require('fs')
.headers - {header: value} - serve headers along the response on each request to the webpack output bundle picked by name
.headers.files - {filename:{header: value}} - the same as .headers but only for a particular webpack output bundle
.filename - String - filename on which request middware starts compilation (lazy mode required)
.publicPath - String - by default '/'
.lazy - Boolean - activate lazy mode so middware compiles bundle by request, false by default
.error - Boolean - log errors, false by default
.debug - Boolean - log debug info, false by default
.quiet - Boolean - log no info about compilation, except errors and debug, false by default


Follow here for more options.
More info about webpack multiple configurations.