Skip to content

Commit 31bcf9b

Browse files
committed
feat(@ngtools/webpack): add AngularCompilerPlugin
1 parent 3068f91 commit 31bcf9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1914
-976
lines changed

package-lock.json

Lines changed: 40 additions & 817 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ export const baseBuildCommandOptions: any = [
176176
aliases: ['nc'],
177177
description: 'Use file name for lazy loaded chunks.',
178178
default: buildConfigDefaults['namedChunks']
179+
},
180+
{
181+
name: 'experimental-angular-compiler',
182+
type: Boolean,
183+
aliases: ['eac'],
184+
description: 'Use new experimental AOT Compiler. This flag is experimental and will go away.',
185+
default: false
179186
}
180187
];
181188

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

Lines changed: 1 addition & 0 deletions
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-configs/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
133133
},
134134
module: {
135135
rules: [
136-
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
136+
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [
137+
nodeModules, /\.ngfactory\.js$/, /\.ngstyle\.js$/
138+
] },
137139
{ test: /\.html$/, loader: 'raw-loader' },
138140
{ test: /\.(eot|svg|cur)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
139141
{

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

Lines changed: 22 additions & 12 deletions
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,27 @@ 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) {
80+
if (!AngularCompilerPlugin.isSupported()) {
81+
throw new Error('You need Angular 5 and up to use --experimentalAngularCompiler.');
82+
}
83+
return new AngularCompilerPlugin(pluginOptions);
84+
} else {
85+
return new AotPlugin(pluginOptions);
86+
}
7787
}
7888

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

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

Lines changed: 5 additions & 1 deletion
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

@@ -212,6 +212,10 @@ class JsonWebpackSerializer {
212212
args = this._aotPluginSerialize(plugin);
213213
this._addImport('@ngtools/webpack', 'AotPlugin');
214214
break;
215+
case AngularCompilerPlugin:
216+
args = this._aotPluginSerialize(plugin);
217+
this._addImport('@ngtools/webpack', 'AngularCompilerPlugin');
218+
break;
215219
case HtmlWebpackPlugin:
216220
args = this._htmlWebpackPlugin(plugin);
217221
this.variableImports['html-webpack-plugin'] = 'HtmlWebpackPlugin';

0 commit comments

Comments
 (0)