From fb072cf6f51b50a9904d88d9fa879d163fca8ed3 Mon Sep 17 00:00:00 2001 From: clydin <19598772+clydin@users.noreply.github.com> Date: Wed, 6 Feb 2019 00:12:31 -0500 Subject: [PATCH] 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 --- .../models/webpack-configs/typescript.ts | 13 ++++--------- packages/ngtools/webpack/src/index.ts | 2 ++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts index 1c5539c6ee77..3971f9621ccc 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts @@ -13,18 +13,13 @@ import * as path from 'path'; import { AngularCompilerPlugin, AngularCompilerPluginOptions, + NgToolsLoader, PLATFORM } from '@ngtools/webpack'; import { buildOptimizerLoader } from './common'; import { WebpackConfigOptions } from '../build-options'; -const g: any = typeof global !== 'undefined' ? global : {}; -const webpackLoader: string = g['_DevKitIsLocal'] - ? require.resolve('@ngtools/webpack') - : '@ngtools/webpack'; - - function _createAotPlugin( wco: WebpackConfigOptions, options: any, @@ -92,7 +87,7 @@ export function getNonAotConfig(wco: WebpackConfigOptions, host: virtualFs.Host< const { tsConfigPath } = wco; return { - module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] }, + module: { rules: [{ test: /\.tsx?$/, loader: NgToolsLoader }] }, plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host)] }; } @@ -104,7 +99,7 @@ export function getAotConfig( ) { const { tsConfigPath, buildOptions } = wco; - const loaders: any[] = [webpackLoader]; + const loaders: any[] = [NgToolsLoader]; if (buildOptions.buildOptimizer) { loaders.unshift({ loader: buildOptimizerLoader, @@ -124,7 +119,7 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions, host: virtualFs.H const { tsConfigPath } = wco; return { - module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] }, + module: { rules: [{ test: /\.tsx?$/, loader: NgToolsLoader }] }, plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host, false)] }; } diff --git a/packages/ngtools/webpack/src/index.ts b/packages/ngtools/webpack/src/index.ts index 0ac24959c8f6..68ee8c1ecb39 100644 --- a/packages/ngtools/webpack/src/index.ts +++ b/packages/ngtools/webpack/src/index.ts @@ -8,3 +8,5 @@ export * from './angular_compiler_plugin'; export { ngcLoader as default } from './loader'; + +export const NgToolsLoader = __filename;