File tree Expand file tree Collapse file tree 3 files changed +155
-0
lines changed Expand file tree Collapse file tree 3 files changed +155
-0
lines changed Original file line number Diff line number Diff line change 1+ # Laravel Mix Vue Css Modules
2+
3+ Add supprt for css module.
4+
5+ ## Installation
6+
7+ ```
8+ npm install laravel-mix-vue-css-modules --save
9+ ```
10+
11+ or
12+
13+ ```
14+ yarn add laravel-mix-vue-css-modules
15+ ```
16+
17+ ## Usage
18+
19+ Your ` webpack.mix.js ` could look like this:
20+
21+ ``` js
22+ const mix = require (" laravel-mix" );
23+ require (" laravel-mix-vue-css-modules" );
24+
25+ mix .vueCssModules ();
26+ ```
27+
28+ custom localIdentName
29+
30+ ``` js
31+ // DEFAULT localIdentName: '[local]_[hash:base64:8]'
32+ mix .vueCssModules ({
33+ localIdentName: " [name]__[local]___[hash:base64:5]" ,
34+ });
35+ ```
36+
37+ switch mode
38+
39+ ``` js
40+ // default global
41+ mix .vueCssModules ({ mode: " local" });
42+ ```
43+
44+ ## Author
45+
46+ Aslam
47+ FullStack Web developer
Original file line number Diff line number Diff line change 1+ const mix = require ( "laravel-mix" ) ;
2+
3+ class VueCssModule {
4+ /**
5+ * Register the component.
6+ *
7+ * When your component is called, all user parameters
8+ * will be passed to this method.
9+ *
10+ * Ex: register(src, output) {}
11+ * Ex: mix.yourPlugin('src/path', 'output/path');
12+ *
13+ * @param {* } ...params
14+ * @return {void }
15+ *
16+ */
17+ register ( {
18+ localIdentName = "[local]_[hash:base64:8]" ,
19+ mode = "global" ,
20+ } = { } ) {
21+ this . localIdentName = localIdentName ;
22+ this . mode = mode ;
23+ }
24+
25+ /**
26+ * Override the generated webpack configuration.
27+ *
28+ * @param {Object } webpackConfig
29+ * @return {void }
30+ */
31+ webpackConfig ( webpackConfig ) {
32+ webpackConfig . module . rules = webpackConfig . module . rules . map ( ( rule ) => {
33+ if ( ! rule . loaders ) {
34+ return rule ;
35+ }
36+
37+ const loaders = rule . loaders . find (
38+ ( loader ) => loader . loader === "css-loader"
39+ ) ;
40+
41+ if ( loaders != undefined ) {
42+ Object . assign ( loaders . options , this [ this . mode ] ( ) ) ;
43+ }
44+
45+ return rule ;
46+ } ) ;
47+
48+ return webpackConfig ;
49+ }
50+
51+ /**
52+ * Return default mode
53+ *
54+ * @return {object }
55+ */
56+ global ( ) {
57+ return {
58+ modules : true ,
59+ localIdentName : this . localIdentName ,
60+ } ;
61+ }
62+
63+ /**
64+ * Return local mode
65+ *
66+ * @return {object }
67+ */
68+ local ( ) {
69+ return {
70+ modules : {
71+ mode : this . mode ,
72+ localIdentName : this . localIdentName ,
73+ } ,
74+ } ;
75+ }
76+ }
77+
78+ mix . extend ( "vueCssModules" , new VueCssModule ( ) ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " laravel-mix-vue-css-modules" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " A Laravel Mix extension for css modules support." ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/Aslam97/laravel-mix-vue-css-modules.git"
12+ },
13+ "keywords" : [
14+ " laravel" ,
15+ " laravel-mix" ,
16+ " mix" ,
17+ " webpack" ,
18+ " vue-css-modules" ,
19+ " modules"
20+ ],
21+ "author" : " Aslam" ,
22+ "license" : " MIT" ,
23+ "bugs" : {
24+ "url" : " https://github.com/Aslam97/laravel-mix-vue-css-modules/issues"
25+ },
26+ "homepage" : " https://github.com/Aslam97/laravel-mix-vue-css-modules#readme" ,
27+ "peerDependencies" : {
28+ "laravel-mix" : " ^5.0.1"
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments