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
+31-3Lines changed: 31 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,7 @@ Please note that no options are required. However, depending on your configurati
74
74
|`classnameTransform`|`asIs`| See [`classnameTransform`](#classnameTransform) below. |
75
75
|`customMatcher`|`"\\.module\\.(c\|le\|sa\|sc)ss$"`| Changes the file extensions that this plugin processes. |
76
76
|`customRenderer`|`false`| See [`customRenderer`](#customRenderer) below. |
77
+
|`customTemplate`|`false`| See [`customTemplate`](#customTemplate) below. |
77
78
|`dotenvOptions`|`{}`| Provides options for [`dotenv`](https://github.com/motdotla/dotenv#options). |
78
79
|`postCssOptions`|`{}`| See [`postCssOptions`](#postCssOptions) below. |
79
80
|`rendererOptions`|`{}`| See [`rendererOptions`](#rendererOptions) below. |
@@ -112,12 +113,12 @@ When a custom renderer is provided, not other renderers will be used.
112
113
113
114
The path to the `customRenderer` must be relative to the project root (i.e. `./myRenderer.js`).
114
115
115
-
The custom renderer itself should be a JavaScript file. The function will be called with two arguments: a `css` string, and an `options` object (see [`options.ts`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/options.ts#L36-L39)). It must be synchronous, and must return valid CSS.
116
+
The custom renderer itself should be a JavaScript file. The function will be called with two arguments: a `css` string, and an `options` object (see [`options.ts`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/options.ts#L33-L41)). It must be synchronous, and must return valid CSS.
116
117
117
118
```js
118
119
module.exports= (css, { fileName, logger }) => {
119
120
try {
120
-
// ...process css here
121
+
// ...process your css here.
121
122
return renderedCss;
122
123
} catch (error) {
123
124
logger.error(error.message);
@@ -129,6 +130,33 @@ You can find an example custom renderer in our test fixtures ([`customRenderer.j
129
130
130
131
The [internal `logger`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/helpers/logger.ts) is provided for [debugging](#troubleshooting).
131
132
133
+
#### `customTemplate`
134
+
135
+
The `customTemplate` is an advanced option, letting you provide a template for the generated TypeScript declarations.
136
+
137
+
When a custom template is provided, its output is used as the virtual declaration (`*.d.ts`) file.
138
+
139
+
The path to the `customTemplate` must be relative to the project root (i.e. `./customTemplate.js`).
140
+
141
+
The custom renderer itself should be a JavaScript file. The function will be called with two arguments: a `dts` string, and an `options` object (see [`options.ts`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/options.ts#L43-L52)). It must be synchronous, and must return a valid TypeScript declaration (as found in a `.d.ts` file).
You can find an example custom template in our test fixtures ([`customTemplate.js`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/helpers/__tests__/fixtures/customTemplate.js)).
155
+
156
+
The [internal `logger`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/master/src/helpers/logger.ts) is provided for [debugging](#troubleshooting).
157
+
158
+
The `classes` object represents all the classnames extracted from the CSS Module. They are available if you want to add a custom representation of the CSS classes.
159
+
132
160
#### `postCssOptions`
133
161
134
162
| Option | Default value | Description |
@@ -171,7 +199,7 @@ If your project doesn't already have global declarations for CSS Modules, you wi
171
199
172
200
Where you store global declarations is up to you. An example might look like: `./src/custom.d.ts`.
173
201
174
-
The below is an example that you can copy or modify. If you use a [`customMatcher`], you'll need to modify this.
202
+
The below is an example that you can copy or modify. If you use a `customMatcher`, you'll need to modify this.
0 commit comments