Skip to content

Commit 19ec95b

Browse files
docs: update splitChunks info (#630)
1 parent 621384c commit 19ec95b

File tree

12 files changed

+101
-6
lines changed

12 files changed

+101
-6
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,16 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
710710
function recursiveIssuer(m) {
711711
if (m.issuer) {
712712
return recursiveIssuer(m.issuer);
713-
} else if (m.name) {
714-
return m.name;
715-
} else {
716-
return false;
717713
}
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;
718723
}
719724

720725
module.exports = {
@@ -726,14 +731,14 @@ module.exports = {
726731
splitChunks: {
727732
cacheGroups: {
728733
fooStyles: {
729-
name: 'foo',
734+
name: 'styles_foo',
730735
test: (m, c, entry = 'foo') =>
731736
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
732737
chunks: 'all',
733738
enforce: true,
734739
},
735740
barStyles: {
736-
name: 'bar',
741+
name: 'styles_bar',
737742
test: (m, c, entry = 'bar') =>
738743
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
739744
chunks: 'all',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_a {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './a.css';
2+
3+
import(/* webpackChunkName: "comp1" */ './components/comp1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_b {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './b.css';
2+
3+
import(/* webpackChunkName: "comp2" */ './components/comp2');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: yellow;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './comp1.css';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: green;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './comp2.css';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.class_a {
2+
background: red;
3+
}
4+
5+
body {
6+
background-color: yellow;
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.class_b {
2+
background: red;
3+
}
4+
5+
body {
6+
background-color: green;
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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: /\.css$/,
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+
};

0 commit comments

Comments
 (0)