Search Terms
automatically resolve custom path aliases in build generated code
Suggestion
I personally can't find the reason why TypeScript does not automatically resolve custom path aliases in the build.
TypeScript is a compiler, so I think that it should take care of that.
To avoid any breaking changes, I think that introducing a new option such as resolveCustomPaths is a good solution.
Use Cases
When I have the paths option set in the tsconfig.json, TypeScript will automatically resolve the import paths in the generated code.
Examples
If I have the following tsconfig.json:
And I have the following /src/app/http/controllers/UserController.ts file:
import { ... } from '@services/my-service.ts';
Would be nice if the UserController.ts could be compiled into something like:
// UserController.js (Compiled)
// BaseURL (tsconfig.json `src`) + CustomPath (tsconfig.json `app/services`) + RequiredFile (`my-service.ts`)
const { ... } = require('src/app/services/my-service.js');
Checklist
My suggestion meets these guidelines:
Search Terms
automatically resolve custom path aliases in build generated code
Suggestion
I personally can't find the reason why TypeScript does not automatically resolve custom path aliases in the build.
TypeScript is a compiler, so I think that it should take care of that.
To avoid any breaking changes, I think that introducing a new option such as
resolveCustomPathsis a good solution.Use Cases
When I have the
pathsoption set in thetsconfig.json, TypeScript will automatically resolve the import paths in the generated code.Examples
If I have the following
tsconfig.json:{ "compilerOptions": { "baseUrl": "src", "paths": { "@core/*": ["app/core/*"] "@services/*": ["app/services/*"] } } }And I have the following
/src/app/http/controllers/UserController.tsfile:Would be nice if the
UserController.tscould be compiled into something like:Checklist
My suggestion meets these guidelines: