Skip to content

Commit 0521818

Browse files
author
Guillaume Chau
committed
docs(css): auto import [ci skip]
1 parent 0f0f7e6 commit 0521818

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/guide/css.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ $color = red;
2525
</style>
2626
```
2727

28+
### Automatic imports
29+
30+
If you want to automatically import files (for colors, variables, mixins...), you can use the [style-resources-loader](https://github.com/yenshih/style-resources-loader). Here is an example for stylus that imports `./src/styles/imports.styl` in every SFC and every stylus files:
31+
32+
```js
33+
// vue.config.js
34+
const path = require('path')
35+
36+
module.exports = {
37+
chainWebpack: config => {
38+
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
39+
types.forEach(type => addStyleResource(config.module.rule('stylus').oneOf(type)))
40+
},
41+
}
42+
43+
function addStyleResource (rule) {
44+
rule.use('style-resource')
45+
.loader('style-resources-loader')
46+
.options({
47+
patterns: [
48+
path.resolve(__dirname, './src/styles/imports.styl'),
49+
],
50+
})
51+
}
52+
```
53+
54+
You can also use the [vue-cli-plugin-style-resources-loader](https://www.npmjs.com/package/vue-cli-plugin-style-resources-loader).
55+
2856
## PostCSS
2957

3058
Vue CLI uses PostCSS internally.

0 commit comments

Comments
 (0)