Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update splitChunks info #637

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
},
Expand Down
20 changes: 13 additions & 7 deletions test/cases/split-chunks-recursiveIssuer/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
},
Expand Down