Skip to content

Commit

Permalink
Fully resolve correct @ngtools/webpack loader (#13549)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
clydin authored and vikerman committed Feb 6, 2019
1 parent 3382dea commit fb072cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
};
}
Expand All @@ -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,
Expand All @@ -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)]
};
}
2 changes: 2 additions & 0 deletions packages/ngtools/webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

export * from './angular_compiler_plugin';
export { ngcLoader as default } from './loader';

export const NgToolsLoader = __filename;

0 comments on commit fb072cf

Please sign in to comment.