To enable CSS Modules language features in your editor, you need to install @css-modules-kit/ts-plugin
(ts-plugin). The installation method varies by editor.
- For VS Code:
- Install the CSS Modules Kit extension
- For Neovim:
- Install
@css-modules-kit/ts-plugin
and set up the configuration
- Install
- For Emacs:
- Not yet supported
- For Zed:
- Not yet supported
- For WebStorm:
- Not yet supported
The ts-plugin provides type definitions for styles
as { foo: string, bar: string }
. However, these types are not applied during type-checking with the tsc
command.
To ensure tsc
properly type-checks, you need to generate *.module.css.d.ts
files. This is handled by codegen.
To install codegen, run the following command:
npm i -D @css-modules-kit/codegen
By default, *.module.css.d.ts
files are generated in the generated
directory.
Finally, you need to configure your tsconfig.json so that the ts-plugin and codegen work correctly.
- Set the
include
option so that files like*.module.css
are considered for type-checking:- For example:
["src"]
,["src/**/*"]
, or omitting theinclude
option (which is equivalent to["**/*"]
) - Not recommended:
["src/**/*.ts"]
,["src/index.ts"]
- For example:
- Set the
rootDirs
option to include both the directory containingtsconfig.json
and thegenerated
directory.- Example:
[".", "generated"]
- Example:
Below is an example configuration:
This completes the minimal setup.
We provide linter plugin for CSS Modules. Currently, we support the following linters:
All linter plugins offer the same set of rules. So please choose and install one.
You can customize the behavior of codegen by adding the cmkOptions
option to your tsconfig.json
. For more details, please refer to Configuration.