File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,20 @@ export = styles;
60
60
### ` banner `
61
61
Adds a "banner" prefix to each generated file.
62
62
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\n declare const styles: {\n ' ;
68
+ for (const c of classes) {
69
+ content += ` ${ c} : string;\n ` ;
70
+ }
71
+ content += ' };\n export default styles;\n ' ;
72
+ return content;
73
+ }
74
+ ```
75
+ ` namedExport ` option will be ignored
76
+
63
77
## Usage in Typescript
64
78
``` ts
65
79
import * as styles from ' ./_button.scss' ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const loaderUtils = require('loader-utils');
7
7
module . exports = function ( content ) {
8
8
this . cacheable && this . cacheable ( ) ;
9
9
10
+ /** @type {{ banner?: string, namedExport?: boolean, customTypings?: (classes: string[]) => string } } */
10
11
const options = loaderUtils . getOptions ( this ) || { } ;
11
12
const callback = this . async ( ) ;
12
13
@@ -18,7 +19,9 @@ module.exports = function(content) {
18
19
19
20
{
20
21
const classes = getClasses ( content ) ;
21
- if ( options . namedExport ) {
22
+ if ( options . customTypings ) {
23
+ typings = options . customTypings ( classes ) ;
24
+ } else if ( options . namedExport ) {
22
25
for ( let c of classes ) {
23
26
typings += `export const ${ c } : string;\n` ;
24
27
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " dts-css-modules-loader" ,
3
- "version" : " 1.0.4 " ,
3
+ "version" : " 1.1.0 " ,
4
4
"description" : " webpack loader to generate typings for css modules" ,
5
5
"dependencies" : {
6
6
"loader-utils" : " ^2.0.0"
You can’t perform that action at this time.
0 commit comments