From bd7e0ba1b9a521aa4dc87a9c0279cba56fd54f27 Mon Sep 17 00:00:00 2001 From: Alexey Lavinsky Date: Fri, 23 Oct 2020 16:14:30 +0300 Subject: [PATCH] docs: update splitChunks info (#637) --- README.md | 17 ++++++++++------ .../webpack.config.js | 20 ++++++++++++------- 2 files changed, 24 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..205f9be5 100644 --- a/test/cases/split-chunks-recursiveIssuer/webpack.config.js +++ b/test/cases/split-chunks-recursiveIssuer/webpack.config.js @@ -2,13 +2,17 @@ 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[0] === '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[0] === '4' ? m._chunks : c.chunkGraph.getModuleChunks(m); for (const chunk of chunks) { return chunk.name; @@ -36,14 +40,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, },