Webpack loader to create TypeScript declarations for CSS Modules
npm install spfx-css-modules-typescript-loader   
src/Component.css will generate src/Component.css.d.ts.
webpack and tsc commands to be run in parallel in CI.
verify mode.
css-modules-typescript-loader directly after css-loader in your webpack config.
js
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
'css-modules-typescript-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
}
};
`
$3
Since the TypeScript declarations are generated by webpack, they may potentially be out of date by the time you run tsc. To ensure your types are up to date, you can run the loader in verify mode, which is particularly useful in CI.
For example:
`js
{
loader: 'css-modules-typescript-loader',
options: {
mode: process.env.CI ? 'verify' : 'emit'
}
}
`
Instead of emitting new TypeScript declarations, this will throw an error if a generated declaration doesn't match the committed one. This allows tsc and webpack to run in parallel in CI, if desired.
This workflow is similar to using the Prettier --list-different` option.