MCPcopy
hub / github.com/webpack/webpack / compression

Function compression

test/statsCases/related-assets/webpack.config.js:13–38  ·  view source on GitHub ↗
(exts)

Source from the content-addressed store, hash-verified

11 * @returns {(compiler: Compiler) => void} callback for comperssion
12 */
13const compression = (exts) => (compiler) => {
14 compiler.hooks.thisCompilation.tap("Test", (compilation) => {
15 compilation.hooks.processAssets.tap(
16 {
17 name: "Test",
18 stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
19 },
20 () => {
21 for (const asset of compilation.getAssets()) {
22 for (const ext of exts) {
23 if (asset.name.endsWith(".jpg")) {
24 continue;
25 }
26 const newFile = `${asset.name}${ext}`;
27 compilation.emitAsset(newFile, asset.source);
28 compilation.updateAsset(asset.name, asset.source, {
29 related: {
30 compressed: ["...", newFile]
31 }
32 });
33 }
34 }
35 }
36 );
37 });
38};
39
40/**
41 * @param {string} name name

Callers 1

baseFunction · 0.85

Calls 4

tapMethod · 0.80
getAssetsMethod · 0.80
emitAssetMethod · 0.80
updateAssetMethod · 0.80

Tested by

no test coverage detected