1 |
|
2 |
|
3 | "use strict";
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | class SuppressExtractedTextChunksWebpackPlugin {
|
6 | constructor() { }
|
7 | apply(compiler) {
|
8 | compiler.plugin('compilation', function (compilation) {
|
9 |
|
10 | const cssOnlyChunks = [];
|
11 | const entryPoints = compilation.options.entry;
|
12 |
|
13 | for (let entryPoint of Object.keys(entryPoints)) {
|
14 | if (entryPoints[entryPoint].every((el) => el.match(/\.(css|scss|sass|less|styl)$/))) {
|
15 | cssOnlyChunks.push(entryPoint);
|
16 | }
|
17 | }
|
18 |
|
19 | compilation.plugin('after-seal', (callback) => {
|
20 | compilation.chunks
|
21 | .filter((chunk) => cssOnlyChunks.indexOf(chunk.name) !== -1)
|
22 | .forEach((chunk) => {
|
23 | let newFiles = [];
|
24 | chunk.files.forEach((file) => {
|
25 | if (file.match(/\.js(\.map)?$/)) {
|
26 |
|
27 | delete compilation.assets[file];
|
28 | }
|
29 | else {
|
30 | newFiles.push(file);
|
31 | }
|
32 | });
|
33 | chunk.files = newFiles;
|
34 | });
|
35 | callback();
|
36 | });
|
37 |
|
38 |
|
39 | compilation.plugin('html-webpack-plugin-alter-asset-tags', (htmlPluginData, callback) => {
|
40 | const filterFn = (tag) => !(tag.tagName === 'script' && tag.attributes.src.match(/\.css$/));
|
41 | htmlPluginData.head = htmlPluginData.head.filter(filterFn);
|
42 | htmlPluginData.body = htmlPluginData.body.filter(filterFn);
|
43 | callback(null, htmlPluginData);
|
44 | });
|
45 | });
|
46 | }
|
47 | }
|
48 | exports.SuppressExtractedTextChunksWebpackPlugin = SuppressExtractedTextChunksWebpackPlugin;
|
49 |
|
\ | No newline at end of file |