From 3403b3a0fceed3d178e87d1d73dbec59cf1c8a13 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Fri, 23 Oct 2020 15:50:03 +0300 Subject: [PATCH 1/2] docs: update splitChunks info --- README.md | 17 +++++++++++------ .../webpack.config.js | 19 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7640b6db..9c4a5094 100644 --- a/README.md +++ b/README.md @@ -767,12 +767,15 @@ This also prevents the CSS duplication issue one had with the ExtractTextPlugin. const path = require('path'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -function recursiveIssuer(m) { - if (m.issuer) { - return recursiveIssuer(m.issuer); +function recursiveIssuer(m, c) { + const issuer = c.moduleGraph.getIssuer(m); + // For webpack@4 chunks = m.issuer + + if (issuer) { + return recursiveIssuer(issuer, c); } - const chunks = m.getChunks(); + const chunks = c.chunkGraph.getModuleChunks(m); // For webpack@4 chunks = m._chunks for (const chunk of chunks) { @@ -793,14 +796,16 @@ module.exports = { fooStyles: { name: 'styles_foo', test: (m, c, entry = 'foo') => - m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, + m.constructor.name === 'CssModule' && + recursiveIssuer(m, c) === entry, chunks: 'all', enforce: true, }, barStyles: { name: 'styles_bar', test: (m, c, entry = 'bar') => - m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, + m.constructor.name === 'CssModule' && + recursiveIssuer(m, c) === entry, chunks: 'all', enforce: true, }, diff --git a/test/cases/split-chunks-recursiveIssuer/webpack.config.js b/test/cases/split-chunks-recursiveIssuer/webpack.config.js index fb02ef58..7bf20986 100644 --- a/test/cases/split-chunks-recursiveIssuer/webpack.config.js +++ b/test/cases/split-chunks-recursiveIssuer/webpack.config.js @@ -2,13 +2,16 @@ import { version as webpackVersion } from 'webpack'; import Self from '../../../src'; -function recursiveIssuer(m) { - if (m.issuer) { - return recursiveIssuer(m.issuer); +function recursiveIssuer(m, c) { + const issuer = webpackVersion === '4' ? m.issuer : c.moduleGraph.getIssuer(m); + + if (issuer) { + return recursiveIssuer(issuer, c); } - // eslint-disable-next-line no-underscore-dangle - const chunks = webpackVersion === '4' ? m._chunks : m.getChunks(); + const chunks = + // eslint-disable-next-line no-underscore-dangle + webpackVersion === '4' ? m._chunks : c.chunkGraph.getModuleChunks(m); for (const chunk of chunks) { return chunk.name; @@ -36,14 +39,16 @@ module.exports = { aStyles: { name: 'styles_a', test: (m, c, entry = 'a') => - m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, + m.constructor.name === 'CssModule' && + recursiveIssuer(m, c) === entry, chunks: 'all', enforce: true, }, bStyles: { name: 'styles_b', test: (m, c, entry = 'b') => - m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, + m.constructor.name === 'CssModule' && + recursiveIssuer(m, c) === entry, chunks: 'all', enforce: true, }, From 021c98f5186d3bfa7870d50a228b9d2f2e227f4c Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Fri, 23 Oct 2020 16:01:42 +0300 Subject: [PATCH 2/2] docs: update splitChunks info --- test/cases/split-chunks-recursiveIssuer/webpack.config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/cases/split-chunks-recursiveIssuer/webpack.config.js b/test/cases/split-chunks-recursiveIssuer/webpack.config.js index 7bf20986..205f9be5 100644 --- a/test/cases/split-chunks-recursiveIssuer/webpack.config.js +++ b/test/cases/split-chunks-recursiveIssuer/webpack.config.js @@ -3,7 +3,8 @@ import { version as webpackVersion } from 'webpack'; import Self from '../../../src'; function recursiveIssuer(m, c) { - const issuer = webpackVersion === '4' ? m.issuer : c.moduleGraph.getIssuer(m); + const issuer = + webpackVersion[0] === '4' ? m.issuer : c.moduleGraph.getIssuer(m); if (issuer) { return recursiveIssuer(issuer, c); @@ -11,7 +12,7 @@ function recursiveIssuer(m, c) { const chunks = // eslint-disable-next-line no-underscore-dangle - webpackVersion === '4' ? m._chunks : c.chunkGraph.getModuleChunks(m); + webpackVersion[0] === '4' ? m._chunks : c.chunkGraph.getModuleChunks(m); for (const chunk of chunks) { return chunk.name;