Skip to content

Commit 939cd6c

Browse files
filipesilvahansl
authored andcommittedSep 13, 2017
feat(@ngtools/webpack): add AngularCompilerPlugin
1 parent b0fd35e commit 939cd6c

37 files changed

+1578
-215
lines changed
 

‎package-lock.json

+21-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
"zone.js": "^0.8.14"
103103
},
104104
"devDependencies": {
105-
"@angular/compiler": "^4.0.0",
106-
"@angular/compiler-cli": "^4.0.0",
107-
"@angular/core": "^4.0.0",
105+
"@angular/compiler": "angular/compiler-builds#5.0.0-beta.6+fa6b802",
106+
"@angular/compiler-cli": "angular/compiler-cli-builds#5.0.0-beta.6+fa6b802",
107+
"@angular/core": "angular/core-builds#5.0.0-beta.6+fa6b802",
108108
"@types/chalk": "^0.4.28",
109109
"@types/common-tags": "^1.2.4",
110110
"@types/copy-webpack-plugin": "^4.0.0",

‎packages/@angular/cli/commands/build.ts

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CliConfig } from '../models/config';
22
import { BuildOptions } from '../models/build-options';
33
import { Version } from '../upgrade/version';
44
import { oneLine } from 'common-tags';
5+
import { AngularCompilerPlugin } from '@ngtools/webpack';
56

67
const Command = require('../ember-cli/lib/models/command');
78

@@ -176,6 +177,13 @@ export const baseBuildCommandOptions: any = [
176177
aliases: ['nc'],
177178
description: 'Use file name for lazy loaded chunks.',
178179
default: buildConfigDefaults['namedChunks']
180+
},
181+
{
182+
name: 'experimental-angular-compiler',
183+
type: Boolean,
184+
aliases: ['eac'],
185+
description: 'Use new Angular Compiler (Angular version 5 and greater only).',
186+
default: AngularCompilerPlugin.isSupported()
179187
}
180188
];
181189

‎packages/@angular/cli/models/build-options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export interface BuildOptions {
2525
showCircularDependencies?: boolean;
2626
buildOptimizer?: boolean;
2727
namedChunks?: boolean;
28+
experimentalAngularCompiler?: boolean;
2829
}

‎packages/@angular/cli/models/webpack-config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getAotConfig
1313
} from './webpack-configs';
1414
import * as path from 'path';
15+
import { AngularCompilerPlugin } from '@ngtools/webpack';
1516

1617
export interface WebpackConfigOptions {
1718
projectRoot: string;
@@ -78,6 +79,10 @@ export class NgCliWebpackConfig {
7879
&& !(buildOptions.aot || buildOptions.target === 'production')) {
7980
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
8081
}
82+
83+
if (buildOptions.experimentalAngularCompiler && !AngularCompilerPlugin.isSupported()) {
84+
throw new Error('You need Angular 5 and up to use --experimental-angular-compiler.');
85+
}
8186
}
8287

8388
// Fill in defaults for build targets

‎packages/@angular/cli/models/webpack-configs/common.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
180180
},
181181
module: {
182182
rules: [
183-
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
183+
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [
184+
nodeModules, /\.ngfactory\.js$/, /\.ngstyle\.js$/
185+
] },
184186
{ test: /\.html$/, loader: 'raw-loader' },
185187
{ test: /\.(eot|svg|cur)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
186188
{

‎packages/@angular/cli/models/webpack-configs/typescript.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
22
import { stripIndent } from 'common-tags';
3-
import {AotPlugin} from '@ngtools/webpack';
3+
import { AotPlugin, AngularCompilerPlugin } from '@ngtools/webpack';
44
import { WebpackConfigOptions } from '../webpack-config';
55

66
const SilentError = require('silent-error');
@@ -63,17 +63,24 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
6363
};
6464
}
6565

66-
return new AotPlugin(Object.assign({}, {
67-
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
68-
i18nFile: buildOptions.i18nFile,
69-
i18nFormat: buildOptions.i18nFormat,
70-
locale: buildOptions.locale,
71-
replaceExport: appConfig.platform === 'server',
72-
missingTranslation: buildOptions.missingTranslation,
73-
hostReplacementPaths,
74-
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
75-
exclude: []
76-
}, options));
66+
const pluginOptions = Object.assign({}, {
67+
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
68+
i18nFile: buildOptions.i18nFile,
69+
i18nFormat: buildOptions.i18nFormat,
70+
locale: buildOptions.locale,
71+
replaceExport: appConfig.platform === 'server',
72+
missingTranslation: buildOptions.missingTranslation,
73+
hostReplacementPaths,
74+
sourceMap: buildOptions.sourcemaps,
75+
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
76+
exclude: []
77+
}, options);
78+
79+
if (wco.buildOptions.experimentalAngularCompiler && !options.skipCodeGeneration) {
80+
return new AngularCompilerPlugin(pluginOptions);
81+
} else {
82+
return new AotPlugin(pluginOptions);
83+
}
7784
}
7885

7986
export const getNonAotConfig = function(wco: WebpackConfigOptions) {

‎packages/@angular/cli/models/webpack-xi18n-config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export class XI18nWebpackConfig extends NgCliWebpackConfig {
2424
super({
2525
target: 'development',
2626
verbose: extractOptions.verbose,
27-
progress: extractOptions.progress
27+
progress: extractOptions.progress,
28+
experimentalAngularCompiler: false,
2829
}, appConfig);
2930
super.buildConfig();
3031
}

‎packages/@angular/cli/tasks/eject.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getAppFromConfig } from '../utilities/app-utils';
77
import { EjectTaskOptions } from '../commands/eject';
88
import { NgCliWebpackConfig } from '../models/webpack-config';
99
import { CliConfig } from '../models/config';
10-
import { AotPlugin } from '@ngtools/webpack';
10+
import { AotPlugin, AngularCompilerPlugin } from '@ngtools/webpack';
1111
import { yellow } from 'chalk';
1212
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
1313

@@ -218,6 +218,10 @@ class JsonWebpackSerializer {
218218
args = this._aotPluginSerialize(plugin);
219219
this._addImport('@ngtools/webpack', 'AotPlugin');
220220
break;
221+
case AngularCompilerPlugin:
222+
args = this._aotPluginSerialize(plugin);
223+
this._addImport('@ngtools/webpack', 'AngularCompilerPlugin');
224+
break;
221225
case HtmlWebpackPlugin:
222226
args = this._htmlWebpackPlugin(plugin);
223227
this.variableImports['html-webpack-plugin'] = 'HtmlWebpackPlugin';

‎packages/@ngtools/webpack/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ exports = { /* ... */
2929

3030
The loader works with the webpack plugin to compile your TypeScript. It's important to include both, and to not include any other TypeScript compiler loader.
3131

32+
For Angular version 5 and up, import `AngularCompilerPlugin` instead of `AotPlugin`.
33+
3234
## Options
3335

3436
* `tsConfigPath`. The path to the `tsconfig.json` file. This is required. In your `tsconfig.json`, you can pass options to the Angular Compiler with `angularCompilerOptions`.
3537
* `basePath`. Optional. The root to use by the compiler to resolve file paths. By default, use the `tsConfigPath` root.
3638
* `entryModule`. Optional if specified in `angularCompilerOptions`. The path and classname of the main application module. This follows the format `path/to/file#ClassName`.
3739
* `mainPath`. Optional if `entryModule` is specified. The `main.ts` file containing the bootstrap code. The plugin will use AST to determine the `entryModule`.
38-
* `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.
39-
* `typeChecking`. Optional, defaults to true. Enable type checking through your application. This will slow down compilation, but show syntactic and semantic errors in webpack.
40+
* `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. Only available in `AotPlugin`.
41+
* `typeChecking`. Optional, defaults to true. Enable type checking through your application. This will slow down compilation, but show syntactic and semantic errors in webpack. Only available in `AotPlugin`.
4042
* `exclude`. Optional. Extra files to exclude from TypeScript compilation.
43+
* `sourceMap`. Optional. Include sourcemaps.
4144
* `compilerOptions`. Optional. Override options in `tsconfig.json`.
4245

4346
## Features

0 commit comments

Comments
 (0)
Please sign in to comment.