source: frontend/node_modules/webpack/lib/optimize/RemoveEmptyChunksPlugin.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const { STAGE_ADVANCED, STAGE_BASIC } = require("../OptimizationStages");
9
10/** @typedef {import("../Chunk")} Chunk */
11/** @typedef {import("../Compiler")} Compiler */
12
13const PLUGIN_NAME = "RemoveEmptyChunksPlugin";
14
15class RemoveEmptyChunksPlugin {
16 /**
17 * Applies the plugin by registering its hooks on the compiler.
18 * @param {Compiler} compiler the compiler instance
19 * @returns {void}
20 */
21 apply(compiler) {
22 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
23 /**
24 * Handles the hook callback for this code path.
25 * @param {Iterable<Chunk>} chunks the chunks array
26 * @returns {void}
27 */
28 const handler = (chunks) => {
29 const chunkGraph = compilation.chunkGraph;
30 for (const chunk of chunks) {
31 if (
32 chunkGraph.getNumberOfChunkModules(chunk) === 0 &&
33 !chunk.hasRuntime() &&
34 chunkGraph.getNumberOfEntryModules(chunk) === 0
35 ) {
36 compilation.chunkGraph.disconnectChunk(chunk);
37 compilation.chunks.delete(chunk);
38 }
39 }
40 };
41
42 compilation.hooks.optimizeChunks.tap(
43 {
44 name: PLUGIN_NAME,
45 stage: STAGE_BASIC
46 },
47 handler
48 );
49 compilation.hooks.optimizeChunks.tap(
50 {
51 name: PLUGIN_NAME,
52 stage: STAGE_ADVANCED
53 },
54 handler
55 );
56 });
57 }
58}
59
60module.exports = RemoveEmptyChunksPlugin;
Note: See TracBrowser for help on using the repository browser.