diff --git a/packages/ngtools/webpack/README.md b/packages/ngtools/webpack/README.md index de62be1d00..252a1c687f 100644 --- a/packages/ngtools/webpack/README.md +++ b/packages/ngtools/webpack/README.md @@ -42,6 +42,7 @@ The loader works with webpack plugin to compile your TypeScript. It's important * `skipCodeGeneration`. Optional, defaults to false. Disable code generation and do not refactor the code to bootstrap. This replaces `templateUrl: "string"` with `template: require("string")` (and similar for styles) to allow for webpack to properly link the resources. * `sourceMap`. Optional. Include sourcemaps. * `compilerOptions`. Optional. Override options in `tsconfig.json`. +* `keepAotRemoveDecorators`, Optional. Allows to keep the decorators in AOT production. ## Features The benefits and ability of using [`@ngtools/webpack`](https://www.npmjs.com/~ngtools) standalone from the Angular CLI as presented in [Stephen Fluin's Angular CLI talk](https://youtu.be/uBRK6cTr4Vk?t=6m45s) at Angular Connect 2016: diff --git a/packages/ngtools/webpack/src/angular_compiler_plugin.ts b/packages/ngtools/webpack/src/angular_compiler_plugin.ts index 29136aba54..f58517d434 100644 --- a/packages/ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/ngtools/webpack/src/angular_compiler_plugin.ts @@ -8,7 +8,7 @@ // TODO: fix webpack typings. // tslint:disable-next-line:no-global-tslint-disable // tslint:disable:no-any -import { dirname, normalize, resolve, virtualFs } from '@angular-devkit/core'; +import { virtualFs } from '@angular-devkit/core'; import { ChildProcess, ForkOptions, fork } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; @@ -89,7 +89,10 @@ export interface AngularCompilerPluginOptions { // Use tsconfig to include path globs. compilerOptions?: ts.CompilerOptions; - host?: virtualFs.Host; + host: virtualFs.Host; + + // Allows to keep the decorators in AOT production as an option. + keepAotRemoveDecorators?: boolean; } export enum PLATFORM { @@ -750,7 +753,7 @@ export class AngularCompilerPlugin { if (this._JitMode) { // Replace resources in JIT. this._transformers.push(replaceResources(isAppPath)); - } else { + } else if (this._options.keepAotRemoveDecorators !== true) { // Remove unneeded angular decorators. this._transformers.push(removeDecorators(isAppPath, getTypeChecker)); } @@ -954,13 +957,13 @@ export class AngularCompilerPlugin { const resourceImports = findResources(sourceFile) .map((resourceReplacement) => resourceReplacement.resourcePaths) .reduce((prev, curr) => prev.concat(curr), []) - .map((resourcePath) => resolve(dirname(resolvedFileName), normalize(resourcePath))); + .map((resourcePath) => path.resolve(path.dirname(resolvedFileName), resourcePath)); // These paths are meant to be used by the loader so we must denormalize them. const uniqueDependencies = new Set([ ...esImports, ...resourceImports, - ...this.getResourceDependencies(this._compilerHost.denormalizePath(resolvedFileName)), + ...this.getResourceDependencies(resolvedFileName), ].map((p) => p && this._compilerHost.denormalizePath(p))); return [...uniqueDependencies]