webpack-lru-middleware

raw JSON →
0.1.0 verified Sat Apr 25 auth: no javascript maintenance

A wrapper around webpack-dev-middleware that adds a lazy LRU cache for webpack entrypoints. When using webpack configurations with many entrypoints, it avoids building unused modules by only building entrypoints on demand. Supports preloading initial entries, mapping requests to entrypoint names, and lifecycle hooks. Current stable version is v0.1.0, released in 2017. It is in maintenance mode with no recent updates. It is intended for development use with Express/Connect-like servers.

error Error: Cannot find module 'webpack-lru-middleware'
cause The package is not installed or is installed as a dev dependency but used in runtime.
fix
Run 'npm install webpack-lru-middleware --save-dev' and ensure the import path is correct.
breaking The package is not compatible with webpack 5 without modifications.
fix Use alternative webpack-dev-middleware caching or maintain a fork.
deprecated The package has been unmaintained since 2017 and may not work with modern versions of webpack or Node.js.
fix Consider using webpack's built-in persistent caching or a more recent middleware.
npm install webpack-lru-middleware
yarn add webpack-lru-middleware
pnpm add webpack-lru-middleware

Sets up webpack-lru-middleware with a webpack config, creating a lazy LRU cache for entrypoints.

const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackLRU = require('webpack-lru-middleware');
const path = require('path');

const lru = webpackLRU({
  defaultEntry: { __empty__: path.resolve(__dirname, './empty.js') },
  initialEntry: [],
  mapToEntry: req => path.basename(req.path, '.js'),
});

const webpackConfig = {
  entry: {}, // will be overridden by lru
  output: { filename: '[name].js', path: '/dist' }
};

const compiler = webpack(lru.configure(webpackConfig));
const devMiddleware = webpackDevMiddleware(compiler);

app.use(lru.createMiddleware(devMiddleware));