Skip to content

Commit 3a9d16e

Browse files
committed
Add new option customTypings
Closes #19
1 parent 20da0cd commit 3a9d16e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ export = styles;
6060
### `banner`
6161
Adds a "banner" prefix to each generated file.
6262

63+
### `customTypings`
64+
A function that accepts classes (an array of string) and returns the content of declaration file:
65+
```js
66+
customTypings: classes => {
67+
let content = '// This file is generated automatically\ndeclare const styles: {\n';
68+
for (const c of classes) {
69+
content += ` ${c}: string;\n`;
70+
}
71+
content += '};\nexport default styles;\n';
72+
return content;
73+
}
74+
```
75+
`namedExport` option will be ignored
76+
6377
## Usage in Typescript
6478
```ts
6579
import * as styles from './_button.scss';

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const loaderUtils = require('loader-utils');
77
module.exports = function(content) {
88
this.cacheable && this.cacheable();
99

10+
/** @type {{ banner?: string, namedExport?: boolean, customTypings?: (classes: string[]) => string }} */
1011
const options = loaderUtils.getOptions(this) || {};
1112
const callback = this.async();
1213

@@ -18,7 +19,9 @@ module.exports = function(content) {
1819

1920
{
2021
const classes = getClasses(content);
21-
if (options.namedExport) {
22+
if (options.customTypings) {
23+
typings = options.customTypings(classes);
24+
} else if (options.namedExport) {
2225
for (let c of classes) {
2326
typings += `export const ${c}: string;\n`;
2427
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dts-css-modules-loader",
3-
"version": "1.0.4",
3+
"version": "1.1.0",
44
"description": "webpack loader to generate typings for css modules",
55
"dependencies": {
66
"loader-utils": "^2.0.0"

0 commit comments

Comments
 (0)