* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 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) |
nothing calls this directly
no test coverage detected