ts-extensions-resolver
v1.0.0-alpha.8
Published
Transformer, resolves TS imports and exports extensions
Maintainers
Readme
ts-extensions-resolver
A TypeScript transformer that resolves relative extensions, absolute baseUrl extensions, and path aliases. Supports .ts and .tsx extensions.
Usage
Install Dev Dependencies
npm install -D ts-extensions-resolver ts-node ts-patch typescript@5Add Plugin to tsconfig.json
Add the following configuration to your tsconfig.json:
{
"compilerOptions": {
// ...existing code...
"plugins": [
{
"transform": "ts-extensions-resolver",
"type": "raw"
}
]
}
}Patch tsc
npx ts-patch installHow Does It Work?
Example Project Structure
src
├── index.ts
├── foo
│ └── index.ts
└── bar.tsExample of package.json Build Script
{
// ...existing code...
"scripts": {
"build": "tsc"
}
}Example of tsconfig.json with Paths Aliases and baseUrl
{
"compilerOptions": {
// ...existing code...
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
},
"plugins": [
{
"transform": "ts-extensions-resolver",
"type": "raw"
}
]
}
}TypeScript Source (index.ts)
import {...} from './foo';
import {...} from 'src/bar';
import('@/bar');
export * from '@/bar';Run build Command
npm run buildCompiled JavaScript (index.js)
import {...} from './foo/index.js';
import {...} from './bar.js';
import('./bar.js');
export * from './bar.js';