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

Method apply

lib/asset/AssetModulesPlugin.js:85–377  ·  view source on GitHub ↗

* 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

83 * @returns {void}
84 */
85 apply(compiler) {
86 compiler.hooks.compilation.tap(
87 PLUGIN_NAME,
88 (compilation, { normalModuleFactory }) => {
89 const AssetModule = getAssetModule();
90 for (const type of [
91 ASSET_MODULE_TYPE,
92 ASSET_MODULE_TYPE_BYTES,
93 ASSET_MODULE_TYPE_INLINE,
94 ASSET_MODULE_TYPE_RESOURCE,
95 ASSET_MODULE_TYPE_SOURCE
96 ]) {
97 normalModuleFactory.hooks.createModuleClass
98 .for(type)
99 .tap(
100 PLUGIN_NAME,
101 (createData, _resolveData) =>
102 new AssetModule(createData, this.options.sideEffectFree)
103 );
104 }
105
106 normalModuleFactory.hooks.createParser
107 .for(ASSET_MODULE_TYPE)
108 .tap(PLUGIN_NAME, (parserOptions) => {
109 compiler.validate(
110 () => getSchema("AssetParserOptions"),
111 parserOptions,
112 {
113 name: "Asset Modules Plugin",
114 baseDataPath: "parser"
115 },
116 (options) =>
117 require("../../schemas/plugins/asset/AssetParserOptions.check")(
118 options
119 )
120 );
121
122 let dataUrlCondition = parserOptions.dataUrlCondition;
123 if (!dataUrlCondition || typeof dataUrlCondition === "object") {
124 dataUrlCondition = {
125 maxSize: 8096,
126 ...dataUrlCondition
127 };
128 }
129
130 const AssetParser = getAssetParser();
131
132 return new AssetParser(dataUrlCondition);
133 });
134 normalModuleFactory.hooks.createParser
135 .for(ASSET_MODULE_TYPE_INLINE)
136 .tap(PLUGIN_NAME, (_parserOptions) => {
137 const AssetParser = getAssetParser();
138
139 return new AssetParser(true);
140 });
141 normalModuleFactory.hooks.createParser
142 .for(ASSET_MODULE_TYPE_RESOURCE)

Callers

nothing calls this directly

Calls 14

compareModulesByFullNameFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
getNumberOfErrorsMethod · 0.80
getFullContentHashMethod · 0.80
getFilenameWithInfoMethod · 0.80
getModuleIdMethod · 0.80
getSchemaFunction · 0.70
requireFunction · 0.50
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected