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;
6060### ` banner `
6161Adds 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\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+
6377## Usage in Typescript
6478``` ts
6579import * as styles from ' ./_button.scss' ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const loaderUtils = require('loader-utils');
77module . 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 }
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments