Skip to content

Commit 38570ee

Browse files
committed
add sass-resources-loader for scss in vue
`yarn add --dev sass-resources-loader`
1 parent 2c0d8f6 commit 38570ee

File tree

7 files changed

+1083
-8
lines changed

7 files changed

+1083
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"mini-css-extract-plugin": "^0.9.0",
1818
"sass": "^1.26.9",
1919
"sass-loader": "^8.0.2",
20+
"sass-resources-loader": "^2.0.3",
2021
"vue-loader": "^15.*",
2122
"vue-template-compiler": "^2.6.11",
2223
"webpack": "^4.43.0",

src/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525

2626
<style lang="scss" scoped>
2727
.title {
28-
color: red;
28+
@include text-red
2929
}
3030
</style>

src/css/core/mixin/_mixin.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@mixin text-red {
2+
color: $_color-red;
3+
}

src/css/core/variable/_color.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$_color-red : red;

src/index.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// @import "css/core/variable/color"; // <- included @webpack.config.js
2+
13
body {
24
background-color: #eee;
35
}
6+
7+
address {
8+
color: $_color-red;
9+
}

webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ module.exports = {
3131
fiber: require('fibers')
3232
}
3333
}
34+
},
35+
{
36+
loader: 'sass-resources-loader',
37+
options: {
38+
resources: [
39+
path.resolve(__dirname, 'src/css/core/variable/_color.scss'),
40+
path.resolve(__dirname, 'src/css/core/mixin/_mixin.scss')
41+
]
42+
}
3443
}
3544
]
3645
}

yarn.lock

Lines changed: 1062 additions & 7 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)