Skip to content

Aot watch #7685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2017
Merged
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
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ test_script:
build: off

cache:
- node_modules
- node_modules -> package-lock.json
35 changes: 21 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CliConfig } from '../models/config';
import { BuildOptions } from '../models/build-options';
import { Version } from '../upgrade/version';
import { oneLine } from 'common-tags';
import { AngularCompilerPlugin } from '@ngtools/webpack';

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

Expand Down Expand Up @@ -176,6 +177,13 @@ export const baseBuildCommandOptions: any = [
aliases: ['nc'],
description: 'Use file name for lazy loaded chunks.',
default: buildConfigDefaults['namedChunks']
},
{
name: 'experimental-angular-compiler',
type: Boolean,
// aliases: ['eac'], // We should not have shorthand aliases for experimental flags.
description: '(Experimental) Use new Angular Compiler (Angular version 5 and greater only).',
default: AngularCompilerPlugin.isSupported()
}
];

Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/models/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface BuildOptions {
showCircularDependencies?: boolean;
buildOptimizer?: boolean;
namedChunks?: boolean;
experimentalAngularCompiler?: boolean;
}
5 changes: 5 additions & 0 deletions packages/@angular/cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getAotConfig
} from './webpack-configs';
import * as path from 'path';
import { AngularCompilerPlugin } from '@ngtools/webpack';

export interface WebpackConfigOptions {
projectRoot: string;
Expand Down Expand Up @@ -78,6 +79,10 @@ export class NgCliWebpackConfig {
&& !(buildOptions.aot || buildOptions.target === 'production')) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}

if (buildOptions.experimentalAngularCompiler && !AngularCompilerPlugin.isSupported()) {
throw new Error('You need Angular 5 and up to use --experimental-angular-compiler.');
}
}

// Fill in defaults for build targets
Expand Down
4 changes: 3 additions & 1 deletion packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
},
module: {
rules: [
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [
nodeModules, /\.ngfactory\.js$/, /\.ngstyle\.js$/
] },
{ test: /\.html$/, loader: 'raw-loader' },
{ test: /\.(eot|svg|cur)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
{
Expand Down
31 changes: 19 additions & 12 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { stripIndent } from 'common-tags';
import {AotPlugin} from '@ngtools/webpack';
import { AotPlugin, AngularCompilerPlugin } from '@ngtools/webpack';
import { WebpackConfigOptions } from '../webpack-config';

const SilentError = require('silent-error');
Expand Down Expand Up @@ -63,17 +63,24 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
};
}

return new AotPlugin(Object.assign({}, {
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
i18nFile: buildOptions.i18nFile,
i18nFormat: buildOptions.i18nFormat,
locale: buildOptions.locale,
replaceExport: appConfig.platform === 'server',
missingTranslation: buildOptions.missingTranslation,
hostReplacementPaths,
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
exclude: []
}, options));
const pluginOptions = Object.assign({}, {
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
i18nFile: buildOptions.i18nFile,
i18nFormat: buildOptions.i18nFormat,
locale: buildOptions.locale,
replaceExport: appConfig.platform === 'server',
missingTranslation: buildOptions.missingTranslation,
hostReplacementPaths,
sourceMap: buildOptions.sourcemaps,
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
exclude: []
}, options);

if (wco.buildOptions.experimentalAngularCompiler && !options.skipCodeGeneration) {
return new AngularCompilerPlugin(pluginOptions);
} else {
return new AotPlugin(pluginOptions);
}
}

export const getNonAotConfig = function(wco: WebpackConfigOptions) {
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/models/webpack-xi18n-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class XI18nWebpackConfig extends NgCliWebpackConfig {
super({
target: 'development',
verbose: extractOptions.verbose,
progress: extractOptions.progress
progress: extractOptions.progress,
experimentalAngularCompiler: false,
}, appConfig);
super.buildConfig();
}
Expand Down
6 changes: 5 additions & 1 deletion packages/@angular/cli/tasks/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getAppFromConfig } from '../utilities/app-utils';
import { EjectTaskOptions } from '../commands/eject';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { CliConfig } from '../models/config';
import { AotPlugin } from '@ngtools/webpack';
import { AotPlugin, AngularCompilerPlugin } from '@ngtools/webpack';
import { yellow } from 'chalk';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';

Expand Down Expand Up @@ -213,6 +213,10 @@ class JsonWebpackSerializer {
args = this._aotPluginSerialize(plugin);
this._addImport('@ngtools/webpack', 'AotPlugin');
break;
case AngularCompilerPlugin:
args = this._aotPluginSerialize(plugin);
this._addImport('@ngtools/webpack', 'AngularCompilerPlugin');
break;
case HtmlWebpackPlugin:
args = this._htmlWebpackPlugin(plugin);
this.variableImports['html-webpack-plugin'] = 'HtmlWebpackPlugin';
Expand Down
7 changes: 5 additions & 2 deletions packages/@ngtools/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ exports = { /* ... */

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.

For Angular version 5 and up, import `AngularCompilerPlugin` instead of `AotPlugin`.

## Options

* `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`.
* `basePath`. Optional. The root to use by the compiler to resolve file paths. By default, use the `tsConfigPath` root.
* `entryModule`. Optional if specified in `angularCompilerOptions`. The path and classname of the main application module. This follows the format `path/to/file#ClassName`.
* `mainPath`. Optional if `entryModule` is specified. The `main.ts` file containing the bootstrap code. The plugin will use AST to determine the `entryModule`.
* `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.
* `typeChecking`. Optional, defaults to true. Enable type checking through your application. This will slow down compilation, but show syntactic and semantic errors in webpack.
* `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`.
* `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`.
* `exclude`. Optional. Extra files to exclude from TypeScript compilation.
* `sourceMap`. Optional. Include sourcemaps.
* `compilerOptions`. Optional. Override options in `tsconfig.json`.

## Features
Expand Down
Loading