Registry / devops / auto-css-modules-webpack-plugin

auto-css-modules-webpack-plugin

JSON →
library1.1.1jsnpmunverified

Automatically detects import or require statements for CSS files and adds a query parameter to mark them as CSS Modules in webpack. Current stable version is 1.1.1, with npm package last updated in March 2023. The plugin works by analyzing the AST during webpack's parse phase, converting statements like `import styles from './index.css'` to `import styles from './index.css?modules'`. Supports default extensions: .css, .less, .sass, .scss, .stylus, .styl. Designed for webpack 4 (>=4.46.0) and 5 (>=5.20.0). Key differentiator: avoids manual configuration of CSS Modules per file by automating the detection based on variable assignment.

npm install auto-css-modules-webpack-plugin
INSTALL
IMPORT
SIG · AUTO-CSS-MODULES-W
A
auto-css-modules-webpack-plugin
devopsjavascriptv1.1.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.

AutoCSSModulesWebpackPlugin
const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin')
import AutoCSSModulesWebpackPlugin from 'auto-css-modules-webpack-plugin'
Package does not ship ESM; CommonJS require is mandatory.
AutoCSSModulesWebpackPlugin
const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin').default
const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin')
If using TypeScript with esModuleInterop, direct require works; otherwise .default may be needed. Check your setup.
webpack configuration
const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin'); module.exports = { plugins: [new AutoCSSModulesWebpackPlugin({ queryFlag: 'modules', extraExtnames: [] })] }
module.exports = { plugins: [new AutoCSSModulesWebpackPlugin()] }
Default options work; but extraExtnames must be provided if using non-standard extensions beyond defaults.

Webpack config with css-loader oneOf rules: CSS files with ?modules query get CSS Modules enabled, others treated as global CSS. Plugin auto-adds ?modules to imports.

const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin'); const path = require('path'); module.exports = { mode: 'development', entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, module: { rules: [ { test: /\.css$/i, oneOf: [ { resourceQuery: /modules/, use: ['style-loader', { loader: 'css-loader', options: { modules: { localIdentName: '[name]__[local]--[hash:base64:5]' } } }] }, { use: ['style-loader', { loader: 'css-loader', options: {} }] } ] } ] }, plugins: [new AutoCSSModulesWebpackPlugin({ queryFlag: 'modules', extraExtnames: [] })] };
Debug
Known issues
gotchaPlugin cannot be used with webpack <4.46.0 or <5.20.0 due to peer dependency range.
fix
Upgrade webpack to version 4.46.0+ or 5.20.0+.
affects: <4.46.0 || <5.20.0
gotchaDefault extname list is fixed and cannot be overwritten; extraExtnames appends to the list but does not replace defaults.
fix
If you need to exclude a default extension, consider a custom webpack rule instead.
affects: >=1.0.0
deprecatedThe package is low maintenance; last update March 2023. May not support future webpack versions.
fix
Consider alternatives like @umijs/babel-plugin-auto-css-modules for newer setups.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'auto-css-modules-webpack-plugin'
Package not installed or missing from node_modules.
fix
Run `npm install --save-dev auto-css-modules-webpack-plugin`.
TypeError: AutoCSSModulesWebpackPlugin is not a constructor
Using import statement instead of require, or missing .default.
fix
Use `const AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin');`.
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type
css-loader not configured correctly or oneOf rules missing.
fix
Add 'style-loader' and 'css-loader' to the webpack config as shown in quickstart.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency - plugin hooks into webpack compiler
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
auto-css-modules-webpack-plugin — npm install auto-css-modules-webpack-plugin · libregistry