HardSourceWebpackPlugin
raw JSON →HardSourceWebpackPlugin is a webpack plugin that provides intermediate caching of module compilation results to disk, drastically speeding up subsequent builds (second build is significantly faster). Version 0.13.1 is the latest stable release, last updated in 2020. It works by caching the output of webpack's module resolution and transformation steps, using a configurable cache directory and hash-based invalidation. Key differentiators: it caches at the module level (not just the entire bundle), supports parallel builds via ParallelModulePlugin, and allows excluding specific modules. However, it is no longer maintained and may have compatibility issues with modern webpack versions (5+), making it less suitable for new projects compared to persistent caching built into webpack 5.
Common errors
error Module not found: Error: Can't resolve 'hard-source-webpack-plugin' ↓
error Error: HardSourceWebpackPlugin is not a constructor ↓
error TypeError: Cannot read property 'tap' of undefined ↓
error Build fails silently with no errors after first build (assets not emitted) ↓
Warnings
deprecated Package is no longer maintained (last release 2020) and may not work with webpack 5+. ↓
breaking HardSourceWebpackPlugin may cause memory leaks or build failures with certain loaders, especially mini-css-extract-plugin. ↓
gotcha First build is not cached; only subsequent builds benefit. Cache must be manually cleared if build configuration changes unexpectedly. ↓
gotcha The package does not support ES module imports (import). Only CommonJS require() works. ↓
gotcha ParallelModulePlugin is experimental and may cause issues with webpack-dev-server or hot module replacement. ↓
Install
npm install hard-source-webpack-plugin yarn add hard-source-webpack-plugin pnpm add hard-source-webpack-plugin Imports
- HardSourceWebpackPlugin wrong
import HardSourceWebpackPlugin from 'hard-source-webpack-plugin'; // ESM not supportedcorrectconst HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); - HardSourceWebpackPlugin.ExcludeModulePlugin wrong
import { ExcludeModulePlugin } from 'hard-source-webpack-plugin'; // ESM not supportedcorrectconst { ExcludeModulePlugin } = require('hard-source-webpack-plugin'); - HardSourceWebpackPlugin.ParallelModulePlugin wrong
const ParallelModulePlugin = require('hard-source-webpack-plugin/parallel'); // wrong pathcorrectconst { ParallelModulePlugin } = require('hard-source-webpack-plugin');
Quickstart
// webpack.config.js
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: { filename: 'bundle.js', path: __dirname + '/dist' },
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',
info: { mode: 'none', level: 'warn' },
}),
],
};