Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 505aac2

Browse files
urishhansl
authored andcommitted
feat(@ngtools/webpack): add .tsx support
1 parent 3cf0aec commit 505aac2

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
224224
mode: buildOptions.optimization ? 'production' : 'development',
225225
devtool: false,
226226
resolve: {
227-
extensions: ['.ts', '.mjs', '.js'],
227+
extensions: ['.ts', '.tsx', '.mjs', '.js'],
228228
symlinks: !buildOptions.preserveSymlinks,
229229
modules: [
230230
wco.tsConfig.options.baseUrl || projectRoot,

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function getNonAotConfig(wco: WebpackConfigOptions, host: virtualFs.Host<
8282
const { tsConfigPath } = wco;
8383

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

116116
return {
117-
module: { rules: [{ test: /\.ts$/, loader: webpackLoader }] },
117+
module: { rules: [{ test: /\.tsx?$/, loader: webpackLoader }] },
118118
plugins: [_createAotPlugin(wco, { tsConfigPath, skipCodeGeneration: true }, host, false)]
119119
};
120120
}

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class AngularCompilerPlugin {
325325

326326
private _getChangedTsFiles() {
327327
return this._compilerHost.getChangedFilePaths()
328-
.filter(k => k.endsWith('.ts') && !k.endsWith('.d.ts'))
328+
.filter(k => (k.endsWith('.ts') || k.endsWith('.tsx')) && !k.endsWith('.d.ts'))
329329
.filter(k => this._compilerHost.fileExists(k));
330330
}
331331

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

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

0 commit comments

Comments
 (0)