Skip to content

Commit fa6795a

Browse files
clydinvikerman
authored andcommitted
Fully resolve correct @ngtools/webpack loader (#13549)
* refactor(@ngtools/webpack): support import-based loader resolution * fix(@angular-devkit/build-angular): ensure correct ngtools loader version By using the the direct import approach, the loader will be guaranteed to originate from the same package version/location as the other `@ngtools/webpack` imports. Fixes #13539
1 parent 0e9cb22 commit fa6795a

File tree

2 files changed

+6
-9
lines changed
  • packages
    • angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs
    • ngtools/webpack/src

2 files changed

+6
-9
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ import * as path from 'path';
1313
import {
1414
AngularCompilerPlugin,
1515
AngularCompilerPluginOptions,
16+
NgToolsLoader,
1617
PLATFORM
1718
} from '@ngtools/webpack';
1819
import { buildOptimizerLoader } from './common';
1920
import { WebpackConfigOptions } from '../build-options';
2021

2122

22-
const g: any = typeof global !== 'undefined' ? global : {};
23-
const webpackLoader: string = g['_DevKitIsLocal']
24-
? require.resolve('@ngtools/webpack')
25-
: '@ngtools/webpack';
26-
27-
2823
function _createAotPlugin(
2924
wco: WebpackConfigOptions,
3025
options: any,
@@ -92,7 +87,7 @@ export function getNonAotConfig(wco: WebpackConfigOptions, host: virtualFs.Host<
9287
const { tsConfigPath } = wco;
9388

9489
return {
95-
module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] },
90+
module: { rules: [{ test: /\.tsx?$/, loader: NgToolsLoader }] },
9691
plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host)]
9792
};
9893
}
@@ -104,7 +99,7 @@ export function getAotConfig(
10499
) {
105100
const { tsConfigPath, buildOptions } = wco;
106101

107-
const loaders: any[] = [webpackLoader];
102+
const loaders: any[] = [NgToolsLoader];
108103
if (buildOptions.buildOptimizer) {
109104
loaders.unshift({
110105
loader: buildOptimizerLoader,
@@ -124,7 +119,7 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions, host: virtualFs.H
124119
const { tsConfigPath } = wco;
125120

126121
return {
127-
module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] },
122+
module: { rules: [{ test: /\.tsx?$/, loader: NgToolsLoader }] },
128123
plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host, false)]
129124
};
130125
}

packages/ngtools/webpack/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88

99
export * from './angular_compiler_plugin';
1010
export { ngcLoader as default } from './loader';
11+
12+
export const NgToolsLoader = __filename;

0 commit comments

Comments
 (0)