Registry / devops / clean-css-loader

clean-css-loader

JSON →
library4.2.1jsnpmunverified

A webpack loader that minifies CSS using CleanCSS. Current stable version is 4.2.1 (released February 2023), with maintenance-level updates. It supports webpack 2+ and works with schema-utils v3/v4, loader-utils v1-v3. Key differentiators: minimal configuration, supports CleanCSS level 2 optimizations, source maps, and inline import options. Competing loaders like css-minimizer-webpack-plugin are more modern but this loader is simpler for basic minification. Ships TypeScript types.

npm install clean-css-loader
INSTALL
IMPORT
SIG · CLEAN-CSS-LOADER
C
clean-css-loader
devopsjavascriptv4.2.1
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.

default
module.exports = { loader: 'clean-css-loader', options: { ... } }
import cleanCssLoader from 'clean-css-loader'
This is a webpack loader, not a module to import in code. Use it in webpack config as a string or object.
inline import
import 'style-loader!css-loader!clean-css-loader!./style.css'
import 'clean-css-loader!./style.css'
Inline import must chain with style-loader and css-loader; omitting them will not produce CSS in the bundle.
webpack rules
use: ['style-loader', 'css-loader', 'clean-css-loader']
use: ['style-loader', 'css-loader', { loader: 'clean-css-loader?level=2' }]
Use options object instead of query string (e.g. `?level=2`) because webpack 5 parses query strings differently; strings like 'true' are not coerced to boolean.

Shows webpack config with clean-css-loader, including conditional disable for dev and CleanCSS level 2 optimization.

// webpack.config.js const isProduction = process.env.NODE_ENV === 'production'; module.exports = { module: { rules: [ { test: /\.css$/, use: [ 'style-loader', 'css-loader', { loader: 'clean-css-loader', options: { disable: !isProduction, skipWarn: false, sourceMap: true, level: 2, compatibility: 'ie9', }, }, ], }, ], }, };
Debug
Known issues
breakingwebpack 5 changes how query string options are parsed: `?skipWarn=true` becomes string 'true' instead of boolean true
fix
Use an options object in webpack config instead of inline query strings.
affects: >=4.2.1
deprecatedNode.js 12 support dropped in v4.2.0
fix
Upgrade to Node.js >=14.
affects: >=4.2.0 <4.2.0
gotchaLoader-utils v3 changed option parsing; boolean values in query strings are not coerced
fix
Use options object or upgrade loader-utils to v3 and pass primitive values correctly.
affects: >=4.2.0
gotchaWhen using with css-minimizer-webpack-plugin, do not use clean-css-loader in minimization step; use one or the other
fix
Remove clean-css-loader if using css-minimizer-webpack-plugin, or configure plugin to use clean-css instead.
affects: *
Errors
Common errors & fixes
Error: CleanCSSLoader is not a constructor
Using import statement on the loader directly in application code instead of webpack config
fix
Do not import 'clean-css-loader' in application JS; only reference it as a string or object in webpack config.
Module not found: Error: Can't resolve 'clean-css-loader' in /path
Package not installed or webpack config missing resolveLoader
fix
Run 'npm install --save-dev clean-css-loader' and ensure node_modules is accessible.
TypeError: this.getOptions is not a function
Using an incompatible version of webpack or loader-utils
fix
Upgrade webpack to >=5 and loader-utils to >=3, or downgrade clean-css-loader to 4.1.x.
Upgrade
Version history
4.2.1latest on npm
Audit
Dependencies
schema-utilsrequiredPeer dependency for options validation
loader-utilsrequiredPeer dependency for loader option parsing, version must match webpack major
webpackrequiredPeer dependency; requires webpack >=2.0.0
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
clean-css-loader — npm install clean-css-loader · libregistry