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
{{ message }}
This repository was archived by the owner on Oct 30, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+59-2Lines changed: 59 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,55 @@ Webpack loader that works as a css-loader drop-in replacement to generate TypeSc
6
6
7
7
Install via npm `npm install --save-dev typings-for-css-modules-loader`
8
8
9
+
## Options
10
+
11
+
Just like any other loader you can specify options e.g. as query-params
12
+
13
+
### css-loader options
14
+
Any option that your installed version of css-loader supports can be used and will be passed to it.
15
+
16
+
### `namedExport`-option
17
+
As your fellow css-developer may tend to use characters like dashes(`-`) that are not valid characters for a typescript variable the default behaviour for this loader is to export an interface as the default export that contains the classnames as properties.
18
+
e.g.:
19
+
```ts
20
+
exportinterfaceIExampleCss {
21
+
'foo':string;
22
+
'bar-baz':string;
23
+
}
24
+
declareconst styles:IExampleCss;
25
+
26
+
exportdefaultstyles;
27
+
```
28
+
29
+
A cleaner way is to expose all classes as named exports, this can be done if you enable the `namedExport`-option.
As mentioned above, this requires classnames to only contain valid typescript characters, thus filtering out all classnames that do not match /^\w+$/i. (feel free to improve that regexp)
36
+
In order to make sure that even classnames with non-legal characters are used it is highly recommended to use the `camelCase`-option as well, that - once passed to the css-loader - makes sure all classnames are transformed to valid variables.
Keep your `webpack.config` as is just instead of using `css-loader` use `typings-for-css-modules-loader`
@@ -30,7 +79,7 @@ webpackConfig.module.loaders: [
30
79
## Example
31
80
32
81
Imagine you have a file `~/my-project/src/component/MyComponent/component.scss` in your project with the following content:
33
-
```
82
+
```css
34
83
.some-class {
35
84
// somestyles
36
85
&.someOtherClass {
@@ -43,7 +92,7 @@ Imagine you have a file `~/my-project/src/component/MyComponent/component.scss`
43
92
```
44
93
45
94
Adding the `typings-for-css-modules-loader` will generate a file `~/my-project/src/component/MyComponent/mycomponent.scss.d.ts` that has the following content:
0 commit comments