* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 75 | * @returns {void} |
| 76 | */ |
| 77 | apply(compiler) { |
| 78 | const options = this.options; |
| 79 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 80 | const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); |
| 81 | new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); |
| 82 | const matchModule = ModuleFilenameHelpers.matchObject.bind( |
| 83 | ModuleFilenameHelpers, |
| 84 | options |
| 85 | ); |
| 86 | hooks.renderModuleContent.tap( |
| 87 | PLUGIN_NAME, |
| 88 | (source, m, { chunk, runtimeTemplate, chunkGraph }) => { |
| 89 | const cachedSource = cache.get(source); |
| 90 | if (cachedSource !== undefined) { |
| 91 | return cachedSource; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns result. |
| 96 | * @param {Source} r result |
| 97 | * @returns {Source} result |
| 98 | */ |
| 99 | const result = (r) => { |
| 100 | cache.set(source, r); |
| 101 | return r; |
| 102 | }; |
| 103 | |
| 104 | if (m instanceof NormalModule) { |
| 105 | if (!matchModule(m.resource)) { |
| 106 | return result(source); |
| 107 | } |
| 108 | } else if (m instanceof ConcatenatedModule) { |
| 109 | if (m.rootModule instanceof NormalModule) { |
| 110 | if (!matchModule(m.rootModule.resource)) { |
| 111 | return result(source); |
| 112 | } |
| 113 | } else { |
| 114 | return result(source); |
| 115 | } |
| 116 | } else { |
| 117 | return result(source); |
| 118 | } |
| 119 | |
| 120 | const namespace = compilation.getPath(this.namespace, { |
| 121 | chunk |
| 122 | }); |
| 123 | /** @type {RawSourceMap} */ |
| 124 | let sourceMap; |
| 125 | /** @type {string | Buffer} */ |
| 126 | let content; |
| 127 | if (source.sourceAndMap) { |
| 128 | const sourceAndMap = source.sourceAndMap(options); |
| 129 | sourceMap = /** @type {RawSourceMap} */ (sourceAndMap.map); |
| 130 | content = sourceAndMap.source; |
| 131 | } else { |
| 132 | sourceMap = /** @type {RawSourceMap} */ (source.map(options)); |
| 133 | content = source.source(); |
| 134 | } |
nothing calls this directly
no test coverage detected