Skip to content

Commit bd7e0ba

Browse files
docs: update splitChunks info (#637)
1 parent a89c0f9 commit bd7e0ba

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,15 @@ This also prevents the CSS duplication issue one had with the ExtractTextPlugin.
767767
const path = require('path');
768768
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
769769

770-
function recursiveIssuer(m) {
771-
if (m.issuer) {
772-
return recursiveIssuer(m.issuer);
770+
function recursiveIssuer(m, c) {
771+
const issuer = c.moduleGraph.getIssuer(m);
772+
// For webpack@4 chunks = m.issuer
773+
774+
if (issuer) {
775+
return recursiveIssuer(issuer, c);
773776
}
774777

775-
const chunks = m.getChunks();
778+
const chunks = c.chunkGraph.getModuleChunks(m);
776779
// For webpack@4 chunks = m._chunks
777780

778781
for (const chunk of chunks) {
@@ -793,14 +796,16 @@ module.exports = {
793796
fooStyles: {
794797
name: 'styles_foo',
795798
test: (m, c, entry = 'foo') =>
796-
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
799+
m.constructor.name === 'CssModule' &&
800+
recursiveIssuer(m, c) === entry,
797801
chunks: 'all',
798802
enforce: true,
799803
},
800804
barStyles: {
801805
name: 'styles_bar',
802806
test: (m, c, entry = 'bar') =>
803-
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
807+
m.constructor.name === 'CssModule' &&
808+
recursiveIssuer(m, c) === entry,
804809
chunks: 'all',
805810
enforce: true,
806811
},

test/cases/split-chunks-recursiveIssuer/webpack.config.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { version as webpackVersion } from 'webpack';
22

33
import Self from '../../../src';
44

5-
function recursiveIssuer(m) {
6-
if (m.issuer) {
7-
return recursiveIssuer(m.issuer);
5+
function recursiveIssuer(m, c) {
6+
const issuer =
7+
webpackVersion[0] === '4' ? m.issuer : c.moduleGraph.getIssuer(m);
8+
9+
if (issuer) {
10+
return recursiveIssuer(issuer, c);
811
}
912

10-
// eslint-disable-next-line no-underscore-dangle
11-
const chunks = webpackVersion === '4' ? m._chunks : m.getChunks();
13+
const chunks =
14+
// eslint-disable-next-line no-underscore-dangle
15+
webpackVersion[0] === '4' ? m._chunks : c.chunkGraph.getModuleChunks(m);
1216

1317
for (const chunk of chunks) {
1418
return chunk.name;
@@ -36,14 +40,16 @@ module.exports = {
3640
aStyles: {
3741
name: 'styles_a',
3842
test: (m, c, entry = 'a') =>
39-
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
43+
m.constructor.name === 'CssModule' &&
44+
recursiveIssuer(m, c) === entry,
4045
chunks: 'all',
4146
enforce: true,
4247
},
4348
bStyles: {
4449
name: 'styles_b',
4550
test: (m, c, entry = 'b') =>
46-
m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
51+
m.constructor.name === 'CssModule' &&
52+
recursiveIssuer(m, c) === entry,
4753
chunks: 'all',
4854
enforce: true,
4955
},

0 commit comments

Comments
 (0)