Skip to content

Commit 27fd9a8

Browse files
westwickyyx990803
authored andcommittedJun 28, 2017
docs: add guide for global scss loading (#861)
* update docs for global scss loading per this comment thread: vuejs/vue-loader#328 (comment) * be more generic about webpack rule * update text

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎docs/en/configurations/pre-processors.md

+34
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@ Contrary to what its name indicates, [*sass*-loader](https://github.com/jtangeld
3737

3838
See the [Advanced Loader Configuration](./advanced.md) Section for further information about how to configure vue-loader.
3939

40+
#### Loading a global settings file
41+
42+
A common request is to be able to load a settings file in each component without the need to explicity import it each time, e.g. to use scss variables globally throughout all components. To accomplish this:
43+
44+
``` bash
45+
npm install sass-resources-loader --save-dev
46+
```
47+
48+
Then add the following webpack rule:
49+
50+
``` js
51+
{
52+
loader: 'sass-resources-loader',
53+
options: {
54+
resources: path.resolve(__dirname, '../src/style/_variables.scss')
55+
}
56+
}
57+
```
58+
59+
As an example, if you are using [vuejs-templates/webpack](https://github.com/vuejs-templates/webpack), modify `build/util.js` like so:
60+
61+
``` js
62+
scss: generateLoaders('sass').concat(
63+
{
64+
loader: 'sass-resources-loader',
65+
options: {
66+
resources: path.resolve(__dirname, '../src/style/_variables.scss')
67+
}
68+
}
69+
),
70+
```
71+
72+
It is recommended to only include variables, mixins, etc. in this file, to prevent duplicated css in your final, compiled files.
73+
4074
### JavaScript
4175

4276
All JavaScript inside Vue components are processed by `babel-loader` by default. But you can of course change it:

0 commit comments

Comments
 (0)
Please sign in to comment.