source: trip-planner-front/node_modules/webpack/lib/optimize/RemoveEmptyChunksPlugin.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 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_BASIC, STAGE_ADVANCED } = require("../OptimizationStages");
9
10/** @typedef {import("../Chunk")} Chunk */
11/** @typedef {import("../Compiler")} Compiler */
12
13class RemoveEmptyChunksPlugin {
14 /**
15 * Apply the plugin
16 * @param {Compiler} compiler the compiler instance
17 * @returns {void}
18 */
19 apply(compiler) {
20 compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
21 /**
22 * @param {Iterable<Chunk>} chunks the chunks array
23 * @returns {void}
24 */
25 const handler = chunks => {
26 const chunkGraph = compilation.chunkGraph;
27 for (const chunk of chunks) {
28 if (
29 chunkGraph.getNumberOfChunkModules(chunk) === 0 &&
30 !chunk.hasRuntime() &&
31 chunkGraph.getNumberOfEntryModules(chunk) === 0
32 ) {
33 compilation.chunkGraph.disconnectChunk(chunk);
34 compilation.chunks.delete(chunk);
35 }
36 }
37 };
38
39 // TODO do it once
40 compilation.hooks.optimizeChunks.tap(
41 {
42 name: "RemoveEmptyChunksPlugin",
43 stage: STAGE_BASIC
44 },
45 handler
46 );
47 compilation.hooks.optimizeChunks.tap(
48 {
49 name: "RemoveEmptyChunksPlugin",
50 stage: STAGE_ADVANCED
51 },
52 handler
53 );
54 });
55 }
56}
57module.exports = RemoveEmptyChunksPlugin;
Note: See TracBrowser for help on using the repository browser.