This case is related to Typescript. You can add typings.d.ts
in your project with this content:
declare module "*.module.css";
declare module "*.module.scss";
It is good practice to use file name with *.module.*
format if you want to enable CSS Module.
css-loader
will enable CSS Module automatically for files with name that satisfy this RegEx: /\.module\.\w+$/i
. This feature is customable by setting options.modules
property as an object.
For example:
import style from './App.module.css'; // CSS Module enabled
import './index.css'; // Plain CSS loaded
For recent configuration, you can add this rule to webpack.config.js
:
{
test: /\.css$/,
use: [
'style-loader',
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[hash:base64]", // default
auto: true // default
},
sourceMap: true
}
},
]
},
A custom configuration example:
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[name]_[local]_[hash:base64]", // custom class name format
auto: /\.cmod\.\w+$/i, // custom auto enable CSS Module for "*.cmod.css" format
},
}
},
Complete documentation is HERE.