Registry / devops / css-hot-loader

css-hot-loader

JSON →
library1.4.4jsnpmunverified

Webpack loader for hot module replacement (HMR) of extracted CSS files, specifically designed to work with extract-text-webpack-plugin and mini-css-extract-plugin. Current stable version is 1.4.4, with low release cadence (last release in 2019). Unlike style-loader (which injects styles via <style> tags and causes FOUC), css-hot-loader enables HMR directly on extracted CSS files while preserving the document styles during JavaScript boot. Requires Webpack 4+ and mini-css-extract-plugin; Webpack 5 compatibility is unclear.

npm install css-hot-loader
INSTALL
IMPORT
SIG · CSS-HOT-LOADER
C
css-hot-loader
devopsjavascriptv1.4.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

css-hot-loader
module.exports = { module: { rules: [ { test: /\.css$/, use: ['css-hot-loader', MiniCssExtractPlugin.loader, 'css-loader'] } ] } }
Loader is used as a string reference in Webpack config, not imported in JS files. Must be placed before MiniCssExtractPlugin.loader.
fileMap option
config: { module: { rules: [ { use: ['css-hot-loader?fileMap=../css/{fileName}', ...] } ] } }
config: { module: { rules: [ { use: ['css-hot-loader', { loader: 'css-hot-loader', options: { fileMap: '../css/{fileName}' } }, ...] } ] } }
Options are passed as query string on the loader string; using options object syntax is not supported.
reloadAll option
config: { module: { rules: [ { use: ['css-hot-loader?reloadAll', ...] } ] } }
config: { module: { rules: [ { use: ['css-hot-loader', { reloadAll: true }, ...] } ] } }
reloadAll is a Boolean flag, enabled by adding the query parameter without a value.
cssModule option
config: { module: { rules: [ { use: ['css-hot-loader?cssModule', ...] } ] } }
config: { module: { rules: [ { use: ['css-hot-loader', { cssModule: true }, ...] } ] } }
When enabled, CSS module changes also trigger JS reload. Pass as query parameter without value.

Webpack config example using css-hot-loader with mini-css-extract-plugin for HMR on extracted CSS

// webpack.config.js const MiniCssExtractPlugin = require('mini-css-extract-plugin'); module.exports = { mode: 'development', entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist' }, module: { rules: [ { test: /\.css$/, use: [ 'css-hot-loader', MiniCssExtractPlugin.loader, 'css-loader' ] } ] }, plugins: [ new MiniCssExtractPlugin({ filename: 'bundle.css' }) ] }; // src/index.js import './style.css'; console.log('CSS HMR with extracted file');
Debug
Known issues
breakingOutput CSS filename must be static; contenthash in filename breaks HMR
fix
Use a static filename like 'bundle.css' or '[name].css' without [contenthash] or [chunkhash]
affects: =1.4.4
gotchacss-hot-loader must be placed before MiniCssExtractPlugin.loader in the use array; otherwise HMR won't work
fix
Ensure loader order: ['css-hot-loader', MiniCssExtractPlugin.loader, 'css-loader']
affects: >=1.0
gotchaOptions must be passed as query string on the loader name, not via options object
fix
Use string syntax: 'css-hot-loader?reloadAll' instead of { loader: 'css-hot-loader', options: { reloadAll: true } }
affects: >=1.0
gotchaWhen using CSS Modules (cssModule option), JS files will also reload on CSS changes, potentially causing full page refresh
fix
Only enable cssModule if you need JS to re-execute on CSS change; otherwise omit the option
affects: >=1.1
deprecatedextract-text-webpack-plugin usage is deprecated; switch to mini-css-extract-plugin for Webpack 4+
fix
Replace extract-text-webpack-plugin with mini-css-extract-plugin and update loader config accordingly
affects: >=1.4
Errors
Common errors & fixes
Error: Cannot find module 'css-hot-loader'
css-hot-loader not installed or not in devDependencies
fix
npm install css-hot-loader --save-dev
Module build failed: TypeError: The 'compilation' argument must be an instance of Compilation
Incompatible with Webpack 5; css-hot-loader v1.4.4 only supports Webpack 4 and below
fix
Use Webpack 4 or consider alternative loaders like style-loader with HMR
HMR: hot reload did not trigger when CSS changed
Output CSS filename contains [contenthash] or dynamic hash, so the loader cannot find the CSS file to reload
fix
Use a static filename in MiniCssExtractPlugin options: filename: 'bundle.css'
Uncaught Error: CSS hot loader: cannot get CSS file path for module
Incorrect fileMap option or CSS/JS entry name mismatch; the loader expects the CSS file to be named same as the JS module
fix
Ensure CSS file path matches JS module name (e.g., src/foo.js -> dist/foo.css). Use fileMap option if needed
Upgrade
Version history
1.4.4latest on npm
Audit
Dependencies
mini-css-extract-pluginrequiredRequired for CSS extraction; the plugin replaces extract-text-webpack-plugin for Webpack 4+
Agent activity
2 hits · last 30 days
node
2
Resources
css-hot-loader — npm install css-hot-loader · libregistry