Webpack loader that generates TypeScript definition files (.d.ts) for CSS Modules, acting as a replacement for the abandoned typings-for-css-modules-loader. Current stable version is 2.0.2. It integrates with css-loader (v2-v7) and requires webpack 5+ (breaking change from v1). Key differentiators: lightweight, no style content modification, supports named exports and custom typings generation via callback. Release cadence is low; last update was 2023.
npm install dts-css-modules-loaderVerified import paths — ran on the pinned version, not inferred.
Configures webpack to use dts-css-modules-loader with named exports and css-loader camelCase convention. Imports individual class names in TypeScript.
Upgrade webpack to version 5, or stay on dts-css-modules-loader v1.x which supports webpack 4.
Set css-loader options.modules.exportLocalsConvention to 'camelCaseOnly' or another convention that produces valid variable names.
Add a global declaration file (e.g., typings.d.ts) with: declare module '*.scss' { const content: any; export default content; }Install or upgrade css-loader to at least version 2.0.0.
Run 'npm install --save-dev dts-css-modules-loader' and ensure the loader name string in webpack config matches exactly.
Reorder the loaders: ['style-loader', 'dts-css-modules-loader', 'css-loader', 'sass-loader'].
Add a declaration file: declare module '*.scss' { export const [classname]: string; export default styles; }Use import * as styles from '...' or switch namedExport to false.