MCPcopy
hub / github.com/angular/angular-cli / apply

Method apply

packages/ngtools/webpack/src/ivy/plugin.ts:139–180  ·  view source on GitHub ↗
(compiler: Compiler)

Source from the content-addressed store, hash-verified

137 }
138
139 apply(compiler: Compiler): void {
140 const { NormalModuleReplacementPlugin, util } = compiler.webpack;
141 this.webpackCreateHash = util.createHash;
142
143 // Setup file replacements with webpack
144 for (const [key, value] of Object.entries(this.pluginOptions.fileReplacements)) {
145 new NormalModuleReplacementPlugin(
146 new RegExp('^' + key.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') + '$'),
147 value,
148 ).apply(compiler);
149 }
150
151 // Set resolver options
152 const pathsPlugin = new TypeScriptPathsPlugin();
153 compiler.hooks.afterResolvers.tap(PLUGIN_NAME, (compiler) => {
154 compiler.resolverFactory.hooks.resolveOptions
155 .for('normal')
156 .tap(PLUGIN_NAME, (resolveOptions) => {
157 resolveOptions.plugins ??= [];
158 resolveOptions.plugins.push(pathsPlugin);
159
160 return resolveOptions;
161 });
162 });
163
164 // Load the compiler-cli if not already available
165 compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, () => this.initializeCompilerCli());
166
167 const compilationState: AngularCompilationState = { pathsPlugin };
168 compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
169 try {
170 this.setupCompilation(compilation, compilationState);
171 } catch (error) {
172 addError(
173 compilation,
174 `Failed to initialize Angular compilation - ${
175 error instanceof Error ? error.message : error
176 }`,
177 );
178 }
179 });
180 }
181
182 private setupCompilation(compilation: Compilation, state: AngularCompilationState): void {
183 const compiler = compilation.compiler;

Callers

nothing calls this directly

Calls 6

initializeCompilerCliMethod · 0.95
setupCompilationMethod · 0.95
addErrorFunction · 0.90
applyMethod · 0.65
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected