Skip to content

Commit 5b3fbef

Browse files
committed
feat: ability to disable extract modules, remove boolean type option
1 parent 81517cc commit 5b3fbef

File tree

15 files changed

+12
-391
lines changed

15 files changed

+12
-391
lines changed

src/index.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class MiniCssExtractPlugin {
177177
);
178178
}
179179

180+
if (module[`${MODULE_TYPE}/disableExtract`]) {
181+
return;
182+
}
183+
180184
const identifierCountMap = new Map();
181185

182186
for (const line of content) {
@@ -206,8 +210,7 @@ class MiniCssExtractPlugin {
206210
pluginName,
207211
(result, { chunk }) => {
208212
const renderedModules = Array.from(chunk.modulesIterable).filter(
209-
(module) =>
210-
module.type === MODULE_TYPE && !moduleToBeRebuild.has(module)
213+
(module) => module.type === MODULE_TYPE
211214
);
212215

213216
if (renderedModules.length > 0) {
@@ -236,8 +239,7 @@ class MiniCssExtractPlugin {
236239
pluginName,
237240
(result, { chunk }) => {
238241
const renderedModules = Array.from(chunk.modulesIterable).filter(
239-
(module) =>
240-
module.type === MODULE_TYPE && !moduleToBeRebuild.has(module)
242+
(module) => module.type === MODULE_TYPE
241243
);
242244

243245
if (renderedModules.length > 0) {
@@ -305,7 +307,7 @@ class MiniCssExtractPlugin {
305307
const { mainTemplate } = compilation;
306308

307309
mainTemplate.hooks.localVars.tap(pluginName, (source, chunk) => {
308-
const chunkMap = this.getCssChunkObject(chunk, compilation);
310+
const chunkMap = this.getCssChunkObject(chunk);
309311

310312
if (Object.keys(chunkMap).length > 0) {
311313
return Template.asString([
@@ -326,7 +328,7 @@ class MiniCssExtractPlugin {
326328
mainTemplate.hooks.requireEnsure.tap(
327329
pluginName,
328330
(source, chunk, hash) => {
329-
const chunkMap = this.getCssChunkObject(chunk, compilation);
331+
const chunkMap = this.getCssChunkObject(chunk);
330332

331333
if (Object.keys(chunkMap).length > 0) {
332334
const chunkMaps = chunk.getChunkMaps();
@@ -499,25 +501,21 @@ class MiniCssExtractPlugin {
499501
shouldDisableExtract({ module, isAsync }) {
500502
const { disableExtract } = this.options;
501503
let shouldDisable = false;
502-
if (disableExtract === true) {
503-
shouldDisable = true;
504-
} else if (typeof disableExtract === 'function') {
504+
if (typeof disableExtract === 'function') {
505505
shouldDisable = disableExtract({ module, isAsync });
506506
}
507507

508508
return shouldDisable;
509509
}
510510

511-
getCssChunkObject(mainChunk, compilation) {
511+
getCssChunkObject(mainChunk) {
512512
const obj = {};
513513

514514
for (const chunk of mainChunk.getAllAsyncChunks()) {
515515
for (const module of chunk.modulesIterable) {
516516
if (module.type === MODULE_TYPE) {
517-
if (!compilation[MODULE_TYPE].moduleToBeRebuild.has(module)) {
518-
obj[chunk.id] = 1;
519-
break;
520-
}
517+
obj[chunk.id] = 1;
518+
break;
521519
}
522520
}
523521
}

test/cases/disable-extract-bool/async-import.css

-3
This file was deleted.

test/cases/disable-extract-bool/async.css

-3
This file was deleted.

test/cases/disable-extract-bool/async.js

-6
This file was deleted.

test/cases/disable-extract-bool/both-async.css

-5
This file was deleted.

test/cases/disable-extract-bool/expected/1.js

-56
This file was deleted.

test/cases/disable-extract-bool/expected/2.js

-13
This file was deleted.

0 commit comments

Comments
 (0)