File tree Expand file tree Collapse file tree 3 files changed +48
-9
lines changed Expand file tree Collapse file tree 3 files changed +48
-9
lines changed Original file line number Diff line number Diff line change @@ -42,15 +42,26 @@ You can then use it in your templates with a dynamic class binding:
42
42
</template >
43
43
```
44
44
45
- ## Parameters
45
+ ## Opt-in Usage
46
+
47
+ If you only want to use CSS Modules in some of your Vue components, you can set `oneOf` to `true`
48
+
49
+ ```js
50
+ mix.vueCssModules({ oneOf : true });
51
+ ```
52
+
53
+ #### Custom localIdentName
54
+
55
+ ``` js
56
+ // DEFAULT: '[local]_[hash:base64:8]'
57
+ mix .vueCssModules ({ localIdentName: " [name]__[local]___[hash:base64:5]" });
58
+ ```
59
+
60
+ #### Local mode
46
61
47
62
``` js
48
- // localIdentName: '[local ]_[hash:base64:8]' // default
49
- // mode
50
- mix.vueCssModules({
51
- localIdentName : " [name]__[local]___[hash:base64:5]" ,
52
- mode: " local" ,
53
- });
63
+ // DEFAULT: global
64
+ mix .vueCssModules ({ mode: " local" });
54
65
```
55
66
56
67
## Author
Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ class VueCssModule {
17
17
register ( {
18
18
localIdentName = "[local]_[hash:base64:8]" ,
19
19
mode = "global" ,
20
+ oneOf = false ,
20
21
} = { } ) {
21
22
this . localIdentName = localIdentName ;
22
23
this . mode = mode ;
24
+ this . oneOf = oneOf ;
23
25
}
24
26
25
27
/**
@@ -39,7 +41,33 @@ class VueCssModule {
39
41
) ;
40
42
41
43
if ( loaders != undefined ) {
42
- Object . assign ( loaders . options , this [ this . mode ] ( ) ) ;
44
+ if ( this . oneOf ) {
45
+ const postCssConfig = rule . loaders . find (
46
+ ( loader ) => loader . loader === "postcss-loader"
47
+ ) ;
48
+
49
+ delete rule . loaders ;
50
+ Object . assign ( rule , {
51
+ test : / \. c s s $ / ,
52
+ oneOf : [
53
+ {
54
+ resourceQuery : / m o d u l e / ,
55
+ use : [
56
+ "style-loader" ,
57
+ {
58
+ loader : "css-loader" ,
59
+ options : this [ this . mode ] ( ) ,
60
+ } ,
61
+ ] ,
62
+ } ,
63
+ {
64
+ use : [ "style-loader" , postCssConfig ] ,
65
+ } ,
66
+ ] ,
67
+ } ) ;
68
+ } else {
69
+ Object . assign ( loaders . options , this [ this . mode ] ( ) ) ;
70
+ }
43
71
}
44
72
45
73
return rule ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " laravel-mix-vue-css-modules" ,
3
- "version" : " 1.0.1 " ,
3
+ "version" : " 1.0.2 " ,
4
4
"description" : " A Laravel Mix extension for css modules support." ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
You can’t perform that action at this time.
0 commit comments