[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.SuppressExtractedTextChunksWebpackPlugin = void 0;
|
---|
| 11 | /**
|
---|
| 12 | * Remove .js files from entry points consisting entirely of stylesheets.
|
---|
| 13 | * To be used together with mini-css-extract-plugin.
|
---|
| 14 | */
|
---|
| 15 | class SuppressExtractedTextChunksWebpackPlugin {
|
---|
| 16 | apply(compiler) {
|
---|
| 17 | compiler.hooks.compilation.tap('SuppressExtractedTextChunks', (compilation) => {
|
---|
| 18 | compilation.hooks.chunkAsset.tap('SuppressExtractedTextChunks', (chunk, filename) => {
|
---|
| 19 | // Remove only JavaScript assets
|
---|
| 20 | if (!filename.endsWith('.js')) {
|
---|
| 21 | return;
|
---|
| 22 | }
|
---|
| 23 | // Only chunks with a css asset should have JavaScript assets removed
|
---|
| 24 | let hasCssFile = false;
|
---|
| 25 | for (const file of chunk.files) {
|
---|
| 26 | if (file.endsWith('.css')) {
|
---|
| 27 | hasCssFile = true;
|
---|
| 28 | break;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 | if (!hasCssFile) {
|
---|
| 32 | return;
|
---|
| 33 | }
|
---|
| 34 | // Only chunks with all CSS entry dependencies should have JavaScript assets removed
|
---|
| 35 | let cssOnly = false;
|
---|
| 36 | const entryModules = compilation.chunkGraph.getChunkEntryModulesIterable(chunk);
|
---|
| 37 | for (const module of entryModules) {
|
---|
| 38 | cssOnly = module.dependencies.every((dependency) => dependency.constructor.name === 'CssDependency');
|
---|
| 39 | if (!cssOnly) {
|
---|
| 40 | break;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | if (cssOnly) {
|
---|
| 44 | chunk.files.delete(filename);
|
---|
| 45 | compilation.deleteAsset(filename);
|
---|
| 46 | }
|
---|
| 47 | });
|
---|
| 48 | });
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | exports.SuppressExtractedTextChunksWebpackPlugin = SuppressExtractedTextChunksWebpackPlugin;
|
---|