Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

feat(@ngtools/webpack): Allows to keep the decorators in AOT producti… #569

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ngtools/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -89,7 +89,10 @@ export interface AngularCompilerPluginOptions {
// Use tsconfig to include path globs.
compilerOptions?: ts.CompilerOptions;

host?: virtualFs.Host<fs.Stats>;
host: virtualFs.Host<fs.Stats>;

// Allows to keep the decorators in AOT production as an option.
keepAotRemoveDecorators?: boolean;
}

export enum PLATFORM {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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]
Expand Down