MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/performance/SizeLimitsPlugin.js:76–188  ·  lib/performance/SizeLimitsPlugin.js::SizeLimitsPlugin.apply

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

74 * @returns {void}
75 */
76 apply(compiler) {
77 const entrypointSizeLimit = this.maxEntrypointSize;
78 const assetSizeLimit = this.maxAssetSize;
79 const hints = this.hints;
80 const assetFilter = this.assetFilter || excludeSourceMap;
81
82 compiler.hooks.afterEmit.tap(PLUGIN_NAME, (compilation) => {
83 /** @type {WebpackError[]} */
84 const warnings = [];
85
86 /**
87 * Gets entrypoint size.
88 * @param {Entrypoint} entrypoint an entrypoint
89 * @returns {number} the size of the entrypoint
90 */
91 const getEntrypointSize = (entrypoint) => {
92 let size = 0;
93 for (const file of entrypoint.getFiles()) {
94 const asset = compilation.getAsset(file);
95 if (
96 asset &&
97 assetFilter(asset.name, asset.source, asset.info) &&
98 asset.source
99 ) {
100 size += asset.info.size || asset.source.size();
101 }
102 }
103 return size;
104 };
105
106 /** @type {AssetDetails[]} */
107 const assetsOverSizeLimit = [];
108 for (const { name, source, info } of compilation.getAssets()) {
109 if (!assetFilter(name, source, info) || !source) {
110 continue;
111 }
112
113 const size = info.size || source.size();
114 if (size > /** @type {number} */ (assetSizeLimit)) {
115 assetsOverSizeLimit.push({
116 name,
117 size
118 });
119 isOverSizeLimitSet.add(source);
120 }
121 }
122
123 /**
124 * Returns result.
125 * @param {Asset[class="st">"name"]} name the name
126 * @returns {boolean | undefined} result
127 */
128 const fileFilter = (name) => {
129 const asset = compilation.getAsset(name);
130 return asset && assetFilter(asset.name, asset.source, asset.info);
131 };
132
133 /** @type {EntrypointDetails[]} */

Callers

nothing calls this directly

Calls 8

tapMethod · 0.80
getAssetsMethod · 0.80
getFilesMethod · 0.80
canBeInitialMethod · 0.80
findFunction · 0.50
sizeMethod · 0.45
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected