Skip to content
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

fix(@ngtools/webpack): fix tsconfig parsing and rootfile list #8215

Merged
merged 4 commits into from
Oct 30, 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
43 changes: 26 additions & 17 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const webpackLoader: string = g['angularCliIsLocal']
: '@ngtools/webpack';


function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = true) {
const { appConfig, projectRoot, buildOptions } = wco;
options.compilerOptions = options.compilerOptions || {};

Expand Down Expand Up @@ -82,7 +82,7 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {

if (AngularCompilerPlugin.isSupported()) {
const pluginOptions: AngularCompilerPluginOptions = Object.assign({}, {
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
mainPath: useMain ? path.join(projectRoot, appConfig.root, appConfig.main) : undefined,
i18nInFile: buildOptions.i18nFile,
i18nInFormat: buildOptions.i18nFormat,
i18nOutFile: buildOptions.i18nOutFile,
Expand All @@ -92,9 +92,6 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
missingTranslation: buildOptions.missingTranslation,
hostReplacementPaths,
sourceMap: buildOptions.sourcemaps,
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
exclude: [],
include: options.include,
}, options);
return new AngularCompilerPlugin(pluginOptions);
} else {
Expand Down Expand Up @@ -163,23 +160,35 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions) {
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.testTsconfig);
const appTsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsconfig);

// Force include main and polyfills.
// This is needed for AngularCompilerPlugin compatibility with existing projects,
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
const include = [appConfig.main, appConfig.polyfills, '**/*.spec.ts'];
if (appConfig.test) {
include.push(appConfig.test);
}
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true };

let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true, include };
if (AngularCompilerPlugin.isSupported()) {
if (appConfig.polyfills) {
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
// include 'polyfills.ts' in `tsconfig.spec.json'.
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
pluginOptions.singleFileIncludes = [polyfillsPath];
}
} else {
// The options below only apply to AoTPlugin.
// Force include main and polyfills.
// This is needed for AngularCompilerPlugin compatibility with existing projects,
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
const include = [appConfig.main, appConfig.polyfills, '**/*.spec.ts'];
if (appConfig.test) {
include.push(appConfig.test);
}

pluginOptions.include = include;

// Fallback to correct module format on projects using a shared tsconfig.
if (tsConfigPath === appTsConfigPath) {
pluginOptions.compilerOptions = { module: 'commonjs' };
// Fallback to correct module format on projects using a shared tsconfig.
if (tsConfigPath === appTsConfigPath) {
pluginOptions.compilerOptions = { module: 'commonjs' };
}
}

return {
module: { rules: [{ test: /\.ts$/, loader: webpackLoader }] },
plugins: [ _createAotPlugin(wco, pluginOptions) ]
plugins: [ _createAotPlugin(wco, pluginOptions, false) ]
};
}
2 changes: 1 addition & 1 deletion packages/@ngtools/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The loader works with webpack plugin to compile your TypeScript. It's important
* `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. 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.
* `exclude`. Optional. Extra files to exclude from TypeScript compilation. Not supported with `AngularCompilerPlugin`.
* `sourceMap`. Optional. Include sourcemaps.
* `compilerOptions`. Optional. Override options in `tsconfig.json`.

Expand Down
Loading