You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-22Lines changed: 36 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,8 +19,8 @@ typed-css-modules creates the following .d.ts files from the above css:
19
19
```ts
20
20
/* styles.css.d.ts */
21
21
declareconst styles: {
22
-
readonly"primary":string;
23
-
readonly"myClass":string;
22
+
readonly primary:string;
23
+
readonly myClass:string;
24
24
};
25
25
export=styles;
26
26
```
@@ -57,6 +57,7 @@ Then, this creates `*.css.d.ts` files under the directory which has original .cs
57
57
```
58
58
59
59
#### output directory
60
+
60
61
Use `-o` or `--outDir` option.
61
62
62
63
For example:
@@ -84,11 +85,12 @@ tcm -p 'src/**/*.icss' .
84
85
```
85
86
86
87
#### watch
88
+
87
89
With `-w` or `--watch`, this CLI watches files in the input directory.
88
90
89
91
#### camelize CSS token
90
-
With `-c` or `--camelCase`, kebab-cased CSS classes(such as `.my-class {...}`) are exported as camelized TypeScript varibale name(`export const myClass: string`).
91
92
93
+
With `-c` or `--camelCase`, kebab-cased CSS classes(such as `.my-class {...}`) are exported as camelized TypeScript varibale name(`export const myClass: string`).
92
94
93
95
You can pass `--camelCase dashes` to only camelize dashes in the class name. Since version `0.27.1` in the
94
96
webpack `css-loader`. This will keep upperCase class names intact, e.g.:
@@ -103,22 +105,23 @@ becomes
103
105
104
106
```typescript
105
107
declareconst styles: {
106
-
readonly"SomeComponent":string;
108
+
readonly SomeComponent:string;
107
109
};
108
110
export=styles;
109
111
```
110
112
111
113
See also [webpack css-loader's camelCase option](https://github.com/webpack/css-loader#camelcase).
112
114
113
115
#### named exports (enable tree shaking)
116
+
114
117
With `-e` or `--namedExports`, types are exported as named exports as opposed to default exports.
115
118
This enables support for the `namedExports` css-loader feature, required for webpack to tree shake the final CSS (learn more [here](https://webpack.js.org/loaders/css-loader/#namedexport)).
116
119
117
120
Use this option in combination with https://webpack.js.org/loaders/css-loader/#namedexport and https://webpack.js.org/loaders/style-loader/#namedexport (if you use `style-loader`).
118
121
119
122
When this option is enabled, the type definition changes to support named exports.
120
123
121
-
*NOTE: this option enables camelcase by default.*
124
+
_NOTE: this option enables camelcase by default._
122
125
123
126
```css
124
127
.SomeComponent {
@@ -130,7 +133,7 @@ When this option is enabled, the type definition changes to support named export
*`option.namedExports`: Use named exports as opposed to default exports to enable tree shaking. Requires `import * as style from './file.module.css';` (default: `false`)
171
-
*`option.EOL`: EOL (end of line) for the generated `d.ts` files. Possible values `'\n'` or `'\r\n'`(default: `os.EOL`).
-`option.namedExports`: Use named exports as opposed to default exports to enable tree shaking. Requires `import * as style from './file.module.css';` (default: `false`)
176
+
-`option.EOL`: EOL (end of line) for the generated `d.ts` files. Possible values `'\n'` or `'\r\n'`(default: `os.EOL`).
Writes the DtsContent instance's content to a file. Returns the DtsContent instance.
184
192
185
-
*`postprocessor` (optional): a function that takes the formatted definition string and returns a modified string that will be the final content written to the file.
193
+
-`postprocessor` (optional): a function that takes the formatted definition string and returns a modified string that will be the final content written to the file.
186
194
187
195
You could use this, for example, to pass generated definitions through a formatter like Prettier, or to add a comment to the top of generated files:
188
196
189
197
```js
190
-
dtsContent.writeFile(
191
-
definition=>`// Generated automatically, do not edit\n${definition}`
192
-
)
198
+
dtsContent.writeFile(definition=>`// Generated automatically, do not edit\n${definition}`);
An array of messages. The messages contains invalid token information.
214
224
e.g. `['my-class is not valid TypeScript variable name.']`.
215
225
216
226
#### `outputFilePath`
227
+
217
228
Final output file path.
218
229
219
230
## Remarks
231
+
220
232
If your input CSS file has the following class names, these invalid tokens are not written to output `.d.ts` file.
221
233
222
234
```css
@@ -227,7 +239,7 @@ If your input CSS file has the following class names, these invalid tokens are n
227
239
228
240
/* invalid TypeScript variable */
229
241
/* If camelCase option is set, this token will be converted to 'myClass' */
230
-
.my-class{
242
+
.my-class{
231
243
color: red;
232
244
}
233
245
@@ -238,9 +250,11 @@ If your input CSS file has the following class names, these invalid tokens are n
238
250
```
239
251
240
252
## Example
253
+
241
254
There is a minimum example in this repository `example` folder. Clone this repository and run `cd example; npm i; npm start`.
242
255
243
256
Or please see [https://github.com/Quramy/typescript-css-modules-demo](https://github.com/Quramy/typescript-css-modules-demo). It's a working demonstration of CSS Modules with React and TypeScript.
244
257
245
258
## License
259
+
246
260
This software is released under the MIT License, see LICENSE.txt.
0 commit comments