File tree 12 files changed +101
-6
lines changed
test/cases/split-chunks-recursiveIssuer
12 files changed +101
-6
lines changed Original file line number Diff line number Diff line change @@ -710,11 +710,16 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
710
710
function recursiveIssuer (m ) {
711
711
if (m .issuer ) {
712
712
return recursiveIssuer (m .issuer );
713
- } else if (m .name ) {
714
- return m .name ;
715
- } else {
716
- return false ;
717
713
}
714
+
715
+ const chunks = m .getChunks ();
716
+ // For webpack@4 chunks = m._chunks
717
+
718
+ for (const chunk of chunks) {
719
+ return chunk .name ;
720
+ }
721
+
722
+ return false ;
718
723
}
719
724
720
725
module .exports = {
@@ -726,14 +731,14 @@ module.exports = {
726
731
splitChunks: {
727
732
cacheGroups: {
728
733
fooStyles: {
729
- name: ' foo ' ,
734
+ name: ' styles_foo ' ,
730
735
test : (m , c , entry = ' foo' ) =>
731
736
m .constructor .name === ' CssModule' && recursiveIssuer (m) === entry,
732
737
chunks: ' all' ,
733
738
enforce: true ,
734
739
},
735
740
barStyles: {
736
- name: ' bar ' ,
741
+ name: ' styles_bar ' ,
737
742
test : (m , c , entry = ' bar' ) =>
738
743
m .constructor .name === ' CssModule' && recursiveIssuer (m) === entry,
739
744
chunks: ' all' ,
Original file line number Diff line number Diff line change
1
+ .class_a {
2
+ background : red;
3
+ }
Original file line number Diff line number Diff line change
1
+ import './a.css' ;
2
+
3
+ import ( /* webpackChunkName: "comp1" */ './components/comp1' ) ;
Original file line number Diff line number Diff line change
1
+ .class_b {
2
+ background : red;
3
+ }
Original file line number Diff line number Diff line change
1
+ import './b.css' ;
2
+
3
+ import ( /* webpackChunkName: "comp2" */ './components/comp2' ) ;
Original file line number Diff line number Diff line change
1
+ body {
2
+ background-color : yellow;
3
+ }
Original file line number Diff line number Diff line change
1
+ import './comp1.css' ;
Original file line number Diff line number Diff line change
1
+ body {
2
+ background-color : green;
3
+ }
Original file line number Diff line number Diff line change
1
+ import './comp2.css' ;
Original file line number Diff line number Diff line change
1
+ .class_a {
2
+ background : red;
3
+ }
4
+
5
+ body {
6
+ background-color : yellow;
7
+ }
8
+
Original file line number Diff line number Diff line change
1
+ .class_b {
2
+ background : red;
3
+ }
4
+
5
+ body {
6
+ background-color : green;
7
+ }
8
+
Original file line number Diff line number Diff line change
1
+ import { version as webpackVersion } from 'webpack' ;
2
+
3
+ import Self from '../../../src' ;
4
+
5
+ function recursiveIssuer ( m ) {
6
+ if ( m . issuer ) {
7
+ return recursiveIssuer ( m . issuer ) ;
8
+ }
9
+
10
+ // eslint-disable-next-line no-underscore-dangle
11
+ const chunks = webpackVersion === '4' ? m . _chunks : m . getChunks ( ) ;
12
+
13
+ for ( const chunk of chunks ) {
14
+ return chunk . name ;
15
+ }
16
+
17
+ return false ;
18
+ }
19
+
20
+ module . exports = {
21
+ entry : {
22
+ a : './a.js' ,
23
+ b : './b.js' ,
24
+ } ,
25
+ module : {
26
+ rules : [
27
+ {
28
+ test : / \. c s s $ / ,
29
+ use : [ Self . loader , 'css-loader' ] ,
30
+ } ,
31
+ ] ,
32
+ } ,
33
+ optimization : {
34
+ splitChunks : {
35
+ cacheGroups : {
36
+ aStyles : {
37
+ name : 'styles_a' ,
38
+ test : ( m , c , entry = 'a' ) =>
39
+ m . constructor . name === 'CssModule' && recursiveIssuer ( m ) === entry ,
40
+ chunks : 'all' ,
41
+ enforce : true ,
42
+ } ,
43
+ bStyles : {
44
+ name : 'styles_b' ,
45
+ test : ( m , c , entry = 'b' ) =>
46
+ m . constructor . name === 'CssModule' && recursiveIssuer ( m ) === entry ,
47
+ chunks : 'all' ,
48
+ enforce : true ,
49
+ } ,
50
+ } ,
51
+ } ,
52
+ } ,
53
+ plugins : [ new Self ( ) ] ,
54
+ } ;
You can’t perform that action at this time.
0 commit comments