webpack-lru-middleware
v0.1.0
Published
Augments webpack-dev-middleware with a lazy LRU cache for entrypoints
Downloads
28,750
Readme
Webpack LRU middleware
Stop building entrypoints you don't need!
The problem
Webpack configurations with a lot of entrypoints will often build a lot of unnecessary modules, taking up valuable build time.
This solution
This module is a wrapper around webpack-dev-middleware, replacing the webpack entry with a cache and mounting entrypoints as they are requested.
- Specify a set of entrypoints on startup
- Build more entrypoints based on trigger requests
- Limit number of active entrypoints to build
- Remove entrypoints when they have not been used for a while
Table of contents
Install
npm install webpack-lru-middleware --save-dev
Usage
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackLRU = require('webpack-lru-middleware');
const lru = webpackLRU({
// Load this file to make webpack happy
defaultEntry: { __empty__: path.resolve(__dirname, './empty.js') },
// Preload these entries on startup
initialEntry: [],
// configure how requests get mapped to entrypoint names:
mapToEntry: req => path.basename(req.path, '.js'),
// lifecycle hooks for logging / debugging purposes:
onAdd: entryName => {},
onRemove: entryName => {},
// LRU Options to configure caching behavior
// passed straight to https://github.com/chriso/lru
lru: {
max: undefined,
maxAge: undefined
}
});
// Pass a modified webpack config with LRU entries to webpack:
const compiler = webpack(lru.configure(webpackConfig));
const middleware = webpackDevMiddleware(compiler);
// Wrap and mount the middlewares:
app.use(lru.createMiddleware(devMiddleware));