Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
feat(@ngtools/webpack): add .tsx support
Browse files Browse the repository at this point in the history
  • Loading branch information
urish authored and hansl committed May 30, 2018
1 parent 3cf0aec commit 505aac2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
mode: buildOptions.optimization ? 'production' : 'development',
devtool: false,
resolve: {
extensions: ['.ts', '.mjs', '.js'],
extensions: ['.ts', '.tsx', '.mjs', '.js'],
symlinks: !buildOptions.preserveSymlinks,
modules: [
wco.tsConfig.options.baseUrl || projectRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getNonAotConfig(wco: WebpackConfigOptions, host: virtualFs.Host<
const { tsConfigPath } = wco;

return {
module: { rules: [{ test: /\.ts$/, loader: webpackLoader }] },
module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] },
plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host)]
};
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions, host: virtualFs.H
const { tsConfigPath } = wco;

return {
module: { rules: [{ test: /\.ts$/, loader: webpackLoader }] },
module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] },
plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host, false)]
};
}
12 changes: 7 additions & 5 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class AngularCompilerPlugin {

private _getChangedTsFiles() {
return this._compilerHost.getChangedFilePaths()
.filter(k => k.endsWith('.ts') && !k.endsWith('.d.ts'))
.filter(k => (k.endsWith('.ts') || k.endsWith('.tsx')) && !k.endsWith('.d.ts'))
.filter(k => this._compilerHost.fileExists(k));
}

Expand Down Expand Up @@ -499,7 +499,7 @@ export class AngularCompilerPlugin {
modulePath = lazyRouteTSFile;
moduleKey = `${lazyRouteModule}${moduleName ? '#' + moduleName : ''}`;
} else {
modulePath = lazyRouteTSFile.replace(/(\.d)?\.ts$/, '');
modulePath = lazyRouteTSFile.replace(/(\.d)?\.tsx?$/, '');
modulePath += '.ngfactory.js';
const factoryModuleName = moduleName ? `#${moduleName}NgFactory` : '';
moduleKey = `${lazyRouteModule}.ngfactory${factoryModuleName}`;
Expand Down Expand Up @@ -686,7 +686,8 @@ export class AngularCompilerPlugin {
// Wait for the plugin to be done when requesting `.ts` files directly (entry points), or
// when the issuer is a `.ts` or `.ngfactory.js` file.
nmf.hooks.beforeResolve.tapAsync('angular-compiler', (request: any, callback: any) => {
if (this.done && (request && request.request.endsWith('.ts')
if (this.done
&& (request && (request.request.endsWith('.ts') || request.request.endsWith('.tsx'))
|| (request && request.context.issuer
&& /\.ts|ngfactory\.js$/.test(request.context.issuer)))) {
this.done.then(() => callback(null, request), () => callback(null, request));
Expand Down Expand Up @@ -893,7 +894,7 @@ export class AngularCompilerPlugin {
}

getCompiledFile(fileName: string) {
const outputFile = fileName.replace(/.ts$/, '.js');
const outputFile = fileName.replace(/.tsx?$/, '.js');
let outputText: string;
let sourceMap: string | undefined;
let errorDependencies: string[] = [];
Expand All @@ -917,7 +918,8 @@ export class AngularCompilerPlugin {
}
} else {
// Check if the TS input file and the JS output file exist.
if ((fileName.endsWith('.ts') && !this._compilerHost.fileExists(fileName, false))
if (((fileName.endsWith('.ts') || fileName.endsWith('.tsx'))
&& !this._compilerHost.fileExists(fileName, false))
|| !this._compilerHost.fileExists(outputFile, false)) {
let msg = `${fileName} is missing from the TypeScript compilation. `
+ `Please make sure it is in your tsconfig via the 'files' or 'include' property.`;
Expand Down

0 comments on commit 505aac2

Please sign in to comment.