Skip to content

Commit 9bde303

Browse files
authored
Update README.md
1 parent bb2e443 commit 9bde303

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

README.md

+45-11
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
## js-to-styles-var-loader
44

5-
### A [Webpack]() loader to share data for sass variables between javascript modules and sass files
5+
### A [Webpack]() loader to share variable data between javascript modules and sass or less files
66

7-
This loader is for that special case when you would like to import data from a javascript module into a sass file. The [sass loader](https://github.com/webpack-contrib/sass-loader) complains, because importing js module is not a valid sass instruction.
7+
This loader is for that special case when you would like to import data from a javascript module into a sass /less file. The [sass](https://github.com/webpack-contrib/sass-loader) / [less](http://lesscss.org/) loader complains, because importing js module is not a valid instruction.
88

9-
##### The loader only handles the case when you want to inject sass variables into a sass file via a javascript module.
9+
##### The loader only handles the case when you want to inject variable data into a sass / less file via a javascript module.
1010

1111
#### Prerequisites
1212

1313
- Nodejs >= 4.0
14-
- [sass](http://sass-lang.com/) for css pre-processing
15-
- Webpack for module bundle
14+
- Webpack for module bundling
1615

1716

1817
#### Setting up Webpack config
1918

20-
Probably you use [sass-loader](https://github.com/webpack-contrib/sass-loader) with Webpack. The usage in this case is pretty simple: just put this loader before sass-loader in your webpack config:
19+
Probably you use [sass-loader](https://github.com/webpack-contrib/sass-loader) or [less-loader](https://github.com/webpack-contrib/less-loader) with Webpack. The usage in this case is pretty simple: just put the js-to-styles-var-loader before the sass-loader / less-loader in your webpack config:
2120

21+
For sass-loader:
2222
```js
2323
{
2424
rules: [
25-
test: /\.sass$/,
25+
test: /\.scss$/,
2626
use: [
2727
{
2828
loader: "style-loader"
@@ -34,13 +34,36 @@ Probably you use [sass-loader](https://github.com/webpack-contrib/sass-loader) w
3434
loader: "sass-loader"
3535
},
3636
{
37-
loader: "js-to-sass-var-loader"
37+
loader: "js-to-styles-var-loader"
3838
}
3939
]
4040
]
4141
}
4242
```
4343

44+
For less-loader:
45+
46+
```js
47+
{
48+
rules: [
49+
test: /\.less$/,
50+
use: [
51+
{
52+
loader: "style-loader"
53+
},
54+
{
55+
loader: "css-loader"
56+
},
57+
{
58+
loader: "less-loader"
59+
},
60+
{
61+
loader: "js-to-styles-var-loader"
62+
}
63+
]
64+
]
65+
}
66+
```
4467
#### Usage
4568

4669
Let's assume we would like to store some variable data in a module like this:
@@ -67,11 +90,22 @@ require('relative/path/to/colors.js');
6790
// ...
6891
```
6992

70-
**The form of the required data is important**: it must be an object with key/values pair, the key will be the name of the sass variable.
93+
**The form of the required data is important**: it must be an object with key/values pair, the key will be the name of the variable.
94+
95+
The js-to-styles-var-loader transforms this sass file and provides it in the following form for the sass-loader:
96+
97+
```js
98+
$fancy-white: #FFFFFE;
99+
$fancy-black: #000001;
100+
101+
.some-class {
102+
background-color: $fancy-white
103+
}
104+
```
71105

72106
#### Misc
73107

74-
You can use other require form (`require('relative/path/to/module').someProperty`), too.
108+
You can use other require forms (`require('relative/path/to/module').someProperty`), too.
75109

76110
#### Demo
77111

@@ -81,7 +115,7 @@ cd demo
81115
npm i
82116
npm run demo
83117
```
84-
The webpack dev server serves the app on `localhost:8030`. In the app we share data between js and sass modules.
118+
The webpack dev server serves the app on `localhost:8030`. In the app we share data between js, less and sass modules.
85119

86120
#### Development
87121

0 commit comments

Comments
 (0)