Skip to content

Commit 96108ad

Browse files
authored
docs(ts-plugin, codegen, vscode, zed): update documentation (#300)
1 parent 4c604fe commit 96108ad

7 files changed

Lines changed: 138 additions & 124 deletions

File tree

.changeset/tame-houses-taste.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@css-modules-kit/ts-plugin': patch
3+
'@css-modules-kit/codegen': patch
4+
'css-modules-kit-vscode': patch
5+
'css-modules-kit-zed': patch
6+
---
7+
8+
docs: update documentation

README.md

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,32 @@ A toolkit for making CSS Modules useful.
1010

1111
By default, CSS Modules have limited language features in editors. For example:
1212

13-
- Clicking on `styles.button` does not go to its definition in `Button.module.css`.
14-
- Renaming `styles.button` does not rename the corresponding `.button {...}` in `Button.module.css`.
15-
- Find all references of `styles.button` does not include its definition in `Button.module.css`.
13+
- Clicking on `styles.button` does not "Go to Definition" in `Button.module.css`.
14+
- Renaming `styles.button` modifies the code in `Button.tsx` but not in `Button.module.css`.
15+
- Performing "Find All References" for `styles.button` finds references in `Button.tsx`, not in `Button.module.css`.
1616

17-
It has been difficult to solve these issues because the TypeScript Language Server (tsserver) does not handle CSS files. Since tsserver does not load CSS files, it cannot determine which definitions to go to or which code to rename.
17+
It has been difficult to solve these issues because the TypeScript Language Server (tsserver) does not load CSS files. TSServer does not know which part of the code to "Go to Definition" for, nor which part of the code to rename.
1818

19-
css-modules-kit solves this problem by using the [TypeScript Language Service Plugin](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin). css-modules-kit extends tsserver to handle `*.module.css` files using it. As a result, rich language features like code navigation and rename refactoring become available. Moreover, it works with various editors.
19+
CSS Modules Kit solves this problem by using the [TypeScript Language Service Plugin](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin) and [Volar.js](https://volarjs.dev/). They extend tsserver to load `*.module.css` files. As a result, [rich language features](#supported-language-features) become available. Moreover, it works with various editors.
2020

21-
css-modules-kit also provides various development tools for CSS Modules. For example, stylelint plugins and the tool that generates `*.d.ts` files.
21+
In addition, CSS Modules Kit provides various tools for CSS Modules (e.g., codegen, linter-plugin). CSS Modules Kit provides you everything you need. It saves you from the hassle of combining multiple third-party tools.
22+
23+
## Get Started
24+
25+
See [docs/get-started.md](./docs/get-started.md).
26+
27+
## Playground
28+
29+
1. Open https://stackblitz.com/~/github.com/mizdra/css-modules-kit-example
30+
2. After waiting a moment, a message will appear in the bottom-right saying `you want to install the recommended extensions`. Click `Install` and wait for the installation to complete.
31+
3. Open `src/a.tsx`. CSS Modules language features should now be enabled.
32+
33+
## Available Tools
34+
35+
- [`@css-modules-kit/ts-plugin`](./packages/ts-plugin/README.md)
36+
- [`@css-modules-kit/codegen`](./packages/codegen/README.md)
37+
- [`@css-modules-kit/stylelint-plugin`](./packages/stylelint-plugin/README.md)
38+
- [`@css-modules-kit/eslint-plugin`](./packages/eslint-plugin/README.md)
2239

2340
## Supported Language Features
2441

@@ -37,7 +54,7 @@ https://github.com/user-attachments/assets/db39a95e-2fc8-42a6-a64d-02f2822afbfe
3754
</details>
3855

3956
<details>
40-
<summary>Find all references</summary>
57+
<summary>Find All References</summary>
4158

4259
https://github.com/user-attachments/assets/df1e2feb-2a1a-4bf5-ae70-1cac36d90409
4360

@@ -73,7 +90,7 @@ https://github.com/user-attachments/assets/05f9e839-9617-43dc-a519-d5a20adf1146
7390

7491
In projects where CSS Modules are used, the element is styled with `className={styles.xxx}`. However, when you type `className`, `className="..."` is completed. This is annoying to the user.
7592

76-
So, instead of `className="..."` instead of `className={...}` instead of `className="..."`.
93+
Therefore, instead of completing `className="..."`, it should complete `className={...}`.
7794

7895
https://github.com/user-attachments/assets/b3609c8a-123f-4f4b-af8c-3c8bf7ab4363
7996

@@ -99,33 +116,9 @@ https://github.com/user-attachments/assets/3502150a-985d-45f3-9912-bbc183e41c03
99116

100117
</details>
101118

102-
## Get Started
103-
104-
Please read the [Get Started](docs/get-started.md) guide.
105-
106-
## How to try demo
107-
108-
1. Open this repository with VS Code
109-
2. Open `Run and Debug` menu
110-
3. Select `vscode (1-basic)` configuration and start debugging
111-
112119
## Configuration
113120

114-
css-modules-kit uses `tsconfig.json` as its configuration file.
115-
116-
### `include`/`exclude`
117-
118-
In TypeScript, the `include`/`exclude` properties specify which `*.ts` files to compile. css-modules-kit reuses these options to determine which `*.module.css` files to handle with codegen and ts-plugin. Therefore, make sure your `*.module.css` files are included in the `include` or `exclude` settings.
119-
120-
```jsonc
121-
{
122-
// For example, if your project's `*.module.css` files are in `src/`:
123-
"include": ["src"], // Default is ["**/*"], so it can be omitted
124-
"compilerOptions": {
125-
// ...
126-
},
127-
}
128-
```
121+
css-modules-kit uses `tsconfig.json` as its configuration file. This configuration only affects the ts-plugin and codegen.
129122

130123
### `cmkOptions.enabled`
131124

@@ -232,23 +225,23 @@ Determines whether to generate the [token](docs/glossary.md#token) of keyframes
232225
}
233226
```
234227

235-
## Supported CSS Modules features
236-
237-
- `:local(...)` and `:global(...)`
238-
- `@keyframes <name> { ... }`
239-
- `@value <name>: <value>;`
240-
- `@value <name>[, <value>]+ from <module-specifier>;`
241-
- `@import <module-specifier>;`
242-
243228
## Limitations
244229

245-
To simplify the implementation, some features are not supported.
230+
Due to implementation constraints and technical reasons, css-modules-kit has various limitations.
246231

247232
- Sass and Less are not supported.
248233
- If you want to use Sass and Less, please use [happy-css-modules](https://github.com/mizdra/happy-css-modules). Although it does not offer as rich language features as css-modules-kit, it provides basic features such as code completion and Go to Definition.
249234
- The name of classes, `@value`, and `@keyframes` must be valid JavaScript identifiers.
250235
- For example, `.fooBar` and `.foo_bar` are supported, but `.foo-bar` is not supported.
251236
- See [#176](https://github.com/mizdra/css-modules-kit/issues/176) for more details.
237+
- The specifiers in `@import '<specifier>'` and `@value ... from '<specifier>'` are resolved according to TypeScript's module resolution method.
238+
- This may differ from the resolution methods of bundlers like Turbopack or Vite.
239+
- If you want to use import aliases, use [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig/#paths) or [`imports`](https://nodejs.org/api/packages.html#imports) in `package.json`.
240+
- Example: `"paths": { "@/*": ["src/*"] }`
241+
- If you want to omit `.css`, use [`compilerOptions.moduleSuffixes`](https://www.typescriptlang.org/tsconfig/#moduleSuffixes).
242+
- Example: `"moduleSuffixes": [".css", ""]`
243+
- If you want to resolve the `style` condition, use [`compilerOptions.customConditions`](https://www.typescriptlang.org/tsconfig/#customConditions).
244+
- Example: `"customConditions": ["style"]`
252245
- `:local .foo {...}` is not supported.
253246
- Use `:local(.foo) {...}` instead.
254247
- `:global .foo {...}` is not supported.

crates/zed/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,4 @@ The Zed extension for CSS Modules Kit
44

55
## Installation
66

7-
1. Install "CSS Modules Kit" extension on Zed.
8-
2. Add the following to your `~./config/zed/settings.json` file:
9-
```json
10-
{
11-
"languages": {
12-
"CSS": {
13-
"language_servers": ["vtsls", "..."]
14-
}
15-
}
16-
}
17-
```
18-
3. Restart Zed.
7+
See [Get Started](https://github.com/mizdra/css-modules-kit/tree/main/packages/ts-plugin#zed).

docs/get-started.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,69 @@
11
# Get Started
22

3+
CSS Modules Kit consists of the following three tools:
4+
5+
- ts-plugin ([`@css-modules-kit/ts-plugin`](../packages/ts-plugin/README.md))
6+
- codegen ([`@css-modules-kit/codegen`](../packages/codegen/README.md))
7+
- linter-plugin ([`@css-modules-kit/stylelint-plugin`](../packages/stylelint-plugin/README.md) or [`@css-modules-kit/eslint-plugin`](../packages/eslint-plugin/README.md))
8+
9+
Each tool is independent and can be used on its own. However, using all three together provides a better developer experience. At minimum, we recommend installing both ts-plugin and codegen.
10+
11+
This guide explains each tool and how to set it up.
12+
313
## Install ts-plugin
414

5-
To enable CSS Modules language features in your editor, you need to install [`@css-modules-kit/ts-plugin`](../packages/ts-plugin/README.md) (ts-plugin). The installation method varies by editor.
6-
7-
- For VS Code:
8-
- Install the [CSS Modules Kit extension](https://marketplace.visualstudio.com/items?itemName=mizdra.css-modules-kit-vscode)
9-
- For Neovim:
10-
- Install [`@css-modules-kit/ts-plugin`](../packages/ts-plugin/README.md#installation) and [set up the configuration](../packages/ts-plugin/README.md)
11-
- For Emacs:
12-
- Not yet supported
13-
- For Zed:
14-
- See [crates/zed/README.md](../crates/zed/README.md)
15-
- For WebStorm:
16-
- Not yet supported
17-
- For StackBlitz Codeflow:
18-
- Install the [CSS Modules Kit extension](https://open-vsx.org/extension/mizdra/css-modules-kit-vscode)
15+
ts-plugin is a TypeScript Language Service Plugin for CSS Modules. Installing ts-plugin enables various language features (see [Supported Language Features](#supported-language-features)).
16+
17+
Installation steps differ depending on your editor. Follow the setup guide below:
18+
19+
- [Installation](../packages/ts-plugin/README.md#installation)
1920

2021
## Install codegen
2122

22-
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.
23+
ts-plugin provides type definitions like `{ foo: string, bar: string }` for `styles`. However, ts-plugin only affects the behavior of the TypeScript Language Server (tsserver). It does not affect `tsc`. Therefore, while `styles` will have the type `{ foo: string, bar: string }` during type checking in the editor, this is not the case for type checking in the terminal.
2324

24-
To ensure `tsc` properly type-checks, you need to generate `*.module.css.d.ts` files. This is handled by codegen.
25+
To achieve the expected type checking in the terminal, `.module.css.d.ts` files are required. codegen is a tool that generates these files.
2526

2627
To install codegen, run the following command:
2728

2829
```bash
2930
npm i -D @css-modules-kit/codegen
3031
```
3132

32-
Configure npm-script to run `cmk` command before building and type checking. This command generates `*.module.css.d.ts` files in `generated` directory.
33+
Configure npm-scripts to run the `cmk` command before building and type checking. Optionally, configure the `cmk --watch` command for debug builds.
3334

3435
```json
3536
{
3637
"scripts": {
37-
"gen": "cmk",
38-
"build": "run-s -c gen build:*",
38+
"generate": "cmk",
39+
"build": "run-s -c generate build:*",
3940
"build:vite": "vite build",
40-
"lint": "run-s -c gen lint:*",
41+
"dev": "run-p dev:*",
42+
"dev:cmk": "cmk --watch",
43+
"dev:vite": "vite",
44+
"lint": "run-s -c generate lint:*",
4145
"lint:eslint": "eslint .",
42-
"lint:tsc": "tsc --noEmit",
43-
"lint:prettier": "prettier --check ."
46+
"lint:tsc": "tsc --noEmit"
4447
}
4548
}
4649
```
4750

51+
By default, `*.module.css.d.ts` files are generated within the `generated` directory. The destination directory can be changed by setting the [`cmkOptions.dtsOutDir`](../README.md#cmkoptionsdtsoutdir) option.
52+
4853
## Configure `tsconfig.json`
4954

50-
Finally, you need to configure your tsconfig.json so that css-modules-kit works correctly.
55+
To enable tsserver and `tsc` to load type definitions generated by CSS Modules Kit, you need to set up `tsconfig.json`.
5156

52-
- Set `cmkOptions.enabled` to `true` to enable css-modules-kit.
53-
- Omit the `include` options or ensure that `*.module.css` files are included when specifying them explicitly.
57+
- Set the [`cmkOptions.enabled`](../README.md#cmkoptionsenabled) option to `true`
58+
- Make sure the [`include`](https://www.typescriptlang.org/tsconfig/#include) option includes `*.module.css` files
5459
- ✅ Good cases:
5560
- Omit `include` (equivalent to `["**/*"]`)
56-
- Use patterns like `["src"]`, `["src/**/*"]`
61+
- `["src"]` (equivalent to `["src/**/*"]`)
62+
- `["src/**/*"]`
5763
- ❌ Bad cases:
5864
- `["src/**/*.ts"]`
59-
- `["src/index.ts"]` (excludes `*.module.css` files)
60-
- Set the `rootDirs` option to include both the directory containing `tsconfig.json` and the `generated` directory.
65+
- `["src/index.ts"]`
66+
- Set the [`rootDirs`](https://www.typescriptlang.org/tsconfig/#rootDirs) option to include both the directory containing `tsconfig.json` and the `generated` directory.
6167
- Example: `[".", "generated"]`
6268

6369
Below is an example configuration:
@@ -74,15 +80,15 @@ Below is an example configuration:
7480
}
7581
```
7682

77-
## Install linter plugin (Optional)
83+
## Install linter-plugin
7884

79-
We provide linter plugin for CSS Modules. Currently, we support the following linters:
85+
The linter-plugin is a linter plugin for `*.module.css` files. Currently, we support the following linters:
8086

8187
- [stylelint-plugin](../packages/stylelint-plugin/README.md)
8288
- [eslint-plugin](../packages/eslint-plugin/README.md)
8389

84-
All linter plugins offer the same set of rules. So please choose and install one.
90+
All linter plugins provide the same set of rules—choose and install whichever you prefer. For installation instructions, refer to their README files.
8591

8692
## Customization (Optional)
8793

88-
You can customize the behavior of codegen by adding the `cmkOptions` option to your `tsconfig.json`. For more details, please refer to [Configuration](../README.md#configuration).
94+
The behavior of ts-plugin and codegen can be customized using the `cmkOptions` option in `tsconfig.json`. For details, see [Configuration](../README.md#configuration).

packages/codegen/README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ A tool for generating `*.d.ts` files for `*.module.css`.
88
npm i -D @css-modules-kit/codegen
99
```
1010

11-
## Requirements
12-
13-
Set `cmkOptions.dtsOutDir` and `"."` to `rootDirs`. This is necessary for the `tsc` command to load the generated `*.d.ts` files.
14-
15-
```json
16-
{
17-
"compilerOptions": {
18-
"rootDirs": [".", "generated"] // Required
19-
},
20-
"cmkOptions": {
21-
"dtsOutDir": "generated" // Default is `"generated"`, so it can be omitted
22-
}
23-
}
24-
```
25-
2611
## Usage
2712

2813
From the command line, run the `cmk` command.

packages/ts-plugin/README.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,70 @@
11
# `@css-modules-kit/ts-plugin`
22

3-
A TypeScript Language Service Plugin for CSS Modules
3+
A TypeScript Language Service Plugin for CSS Modules.
44

5-
## What is this?
5+
## Installation
66

7-
`@css-modules-kit/ts-plugin` is a TypeScript Language Service Plugin that extends tsserver to handle `*.module.css` files. As a result, many language features like code navigation and rename refactoring become available.
7+
### VS Code
88

9-
## Installation
9+
Install the ts-plugin via the Extension. Please install:
10+
11+
- https://marketplace.visualstudio.com/items?itemName=mizdra.css-modules-kit-vscode
12+
13+
### Neovim
14+
15+
First, install ts-plugin globally.
1016

1117
```bash
12-
npm i -D @css-modules-kit/ts-plugin
18+
npm i -g @css-modules-kit/ts-plugin
1319
```
1420

15-
## How to setup your editor
16-
17-
### Neovim
21+
Next, update your LSP client configuration. Below is an example using `nvim-lspconfig`.
1822

1923
```lua
2024
local lspconfig = require('lspconfig')
2125

22-
lspconfig.ts_ls.setup {
23-
init_options = {
24-
plugins = {
25-
{
26-
name = '@css-modules-kit/ts-plugin',
27-
languages = { 'css' },
28-
},
29-
},
30-
},
31-
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'css' },
32-
}
26+
-- TODO: Welcome to contribute
3327
```
3428

29+
### Emacs
30+
31+
First, install ts-plugin globally.
32+
33+
```bash
34+
npm i -g @css-modules-kit/ts-plugin
35+
```
36+
37+
Next, update your LSP client configuration.
38+
39+
TODO: Welcome to contribute
40+
41+
### Zed
42+
43+
Install the ts-plugin via the Extension. Please follow the steps below:
44+
45+
1. Install ["CSS Modules Kit" extension](https://zed.dev/extensions/css-modules-kit).
46+
2. Add the following to your `~./config/zed/settings.json` file:
47+
```json
48+
{
49+
"languages": {
50+
"CSS": {
51+
"language_servers": ["vtsls", "..."]
52+
}
53+
}
54+
}
55+
```
56+
3. Restart Zed.
57+
58+
### WebStorm
59+
60+
Not yet supported.
61+
62+
### StackBlitz Codeflow
63+
64+
Install the ts-plugin via the Extension. Please install:
65+
66+
- https://open-vsx.org/extension/mizdra/css-modules-kit-vscode
67+
3568
## Configuration
3669

37-
See [css-modules-kit's README](https://github.com/mizdra/css-modules-kit?tab=readme-ov-file#configuration).
70+
See [Configuration](https://github.com/mizdra/css-modules-kit?tab=readme-ov-file#configuration).

packages/vscode/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# css-modules-kit-vscode
22

3-
The VS Code extension for CSS Modules
3+
The VS Code extension for CSS Modules.
44

5-
## What is this?
5+
## Installation
66

7-
This is an extension for using `@css-modules-kit/ts-plugin` in VS Code.
7+
See [Get Started](https://github.com/mizdra/css-modules-kit/tree/main/packages/ts-plugin#vs-code).

0 commit comments

Comments
 (0)