{"id":20093,"library":"hard-source-webpack-plugin","title":"HardSourceWebpackPlugin","description":"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.","status":"deprecated","version":"0.13.1","language":"javascript","source_language":"en","source_url":"https://github.com/mzgoddard/hard-source-webpack-plugin","tags":["javascript","webpack","disk","iterative","build","cache","plugin"],"install":[{"cmd":"npm install hard-source-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add hard-source-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add hard-source-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency; plugin works with webpack 4 and earlier, but not fully compatible with webpack 5.","package":"webpack","optional":false}],"imports":[{"note":"The package only supports CommonJS (require). Using ES6 import will fail.","wrong":"import HardSourceWebpackPlugin from 'hard-source-webpack-plugin'; // ESM not supported","symbol":"HardSourceWebpackPlugin","correct":"const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');"},{"note":"ExcludeModulePlugin is a static property on HardSourceWebpackPlugin; destructure require or access via HardSourceWebpackPlugin.ExcludeModulePlugin.","wrong":"import { ExcludeModulePlugin } from 'hard-source-webpack-plugin'; // ESM not supported","symbol":"HardSourceWebpackPlugin.ExcludeModulePlugin","correct":"const { ExcludeModulePlugin } = require('hard-source-webpack-plugin');"},{"note":"ParallelModulePlugin is available as a static property of the main export, not as a separate module.","wrong":"const ParallelModulePlugin = require('hard-source-webpack-plugin/parallel'); // wrong path","symbol":"HardSourceWebpackPlugin.ParallelModulePlugin","correct":"const { ParallelModulePlugin } = require('hard-source-webpack-plugin');"}],"quickstart":{"code":"// webpack.config.js\nconst HardSourceWebpackPlugin = require('hard-source-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: { filename: 'bundle.js', path: __dirname + '/dist' },\n  plugins: [\n    new HardSourceWebpackPlugin({\n      cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',\n      info: { mode: 'none', level: 'warn' },\n    }),\n  ],\n};","lang":"javascript","description":"Shows basic webpack configuration with HardSourceWebpackPlugin for caching modules to disk."},"warnings":[{"fix":"Use webpack 5's built-in persistent caching (cache: { type: 'filesystem' }) instead. For webpack 4, consider using babel-loader's cacheDirectory or other caching strategies.","message":"Package is no longer maintained (last release 2020) and may not work with webpack 5+.","severity":"deprecated","affected_versions":">=0.13.0"},{"fix":"Use ExcludeModulePlugin to exclude problematic loaders, or switch to webpack 5 persistent cache.","message":"HardSourceWebpackPlugin may cause memory leaks or build failures with certain loaders, especially mini-css-extract-plugin.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"Delete the cache directory or use the configHash and environmentHash options to ensure cache invalidation.","message":"First build is not cached; only subsequent builds benefit. Cache must be manually cleared if build configuration changes unexpectedly.","severity":"gotcha","affected_versions":"*"},{"fix":"Use const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');","message":"The package does not support ES module imports (import). Only CommonJS require() works.","severity":"gotcha","affected_versions":"*"},{"fix":"Avoid using ParallelModulePlugin with dev server; consider using webpack's built-in parallelism (webpack 5) or thread-loader.","message":"ParallelModulePlugin is experimental and may cause issues with webpack-dev-server or hot module replacement.","severity":"gotcha","affected_versions":">=0.13.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev hard-source-webpack-plugin and ensure the require path is correct.","cause":"Package not installed or mistaken import path.","error":"Module not found: Error: Can't resolve 'hard-source-webpack-plugin'"},{"fix":"Change import HardSourceWebpackPlugin from ... to const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');","cause":"Using ES6 import instead of CommonJS require.","error":"Error: HardSourceWebpackPlugin is not a constructor"},{"fix":"Downgrade webpack to version 4, or migrate to webpack 5 persistent cache.","cause":"Incompatible version of webpack; HardSourceWebpackPlugin may call hooks not present in webpack 5.","error":"TypeError: Cannot read property 'tap' of undefined"},{"fix":"Add ExcludeModulePlugin to exclude mini-css-extract-loader paths. Example: new HardSourceWebpackPlugin.ExcludeModulePlugin([{ test: /mini-css-extract-plugin[\\\\/]dist[\\\\/]loader/ }])","cause":"Known issue with mini-css-extract-plugin where assets are not emitted on repeated builds.","error":"Build fails silently with no errors after first build (assets not emitted)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}