
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
typescript-transform-paths
Advanced tools
Transforms absolute imports to relative from paths
in your tsconfig.json
npm:
npm i -D typescript-transform-paths
yarn:
yarn add -D typescript-transform-paths
Add it to plugins in your tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@utils/*": ["utils/*"]
},
"plugins": [{ "transform": "typescript-transform-paths" }]
}
}
If you want to generate declaration (.d.ts) files with transformed paths you have to modify your tsconfig.json file:
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@utils/*": ["utils/*"]
},
"declaration": true,
"plugins": [
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
See issue4 for more information.
TS allows defining
virtual directories
via the rootDirs
compiler option. To enable virtual directory mapping, use the useRootDirs
plugin option.
{
"compilerOptions": {
"rootDirs": [ "src", "generated" ],
"baseUrl": ".",
"paths": {
"#root/*": [ "./src/*", "./generated/*" ]
},
"plugins": [
{ "transform": "typescript-transform-paths", useRootDirs: true },
]
}
}
- src/
- subdir/
- sub-file.ts
- file1.ts
- generated/
- file2.ts
src/file1.ts
import '#root/file2.ts' // resolves to './file2'
src/subdir/sub-file.ts
import '#root/file2.ts' // resolves to '../file2'
import '#root/file1.ts' // resolves to '../file1'
// tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@utils/*": ["utils/*"]
}
}
}
// core/index.ts
import { sum } from "@utils/sum";
sum(2, 3);
Gets compiled to:
// core/index.js
var sum_1 = require("../utils/sum");
sum_1.sum(2, 3);
npm install --global prettier
prettier --write src/index.ts
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Transforms module resolution paths using TypeScript path mapping and/or custom paths
The npm package typescript-transform-paths receives a total of 244,501 weekly downloads. As such, typescript-transform-paths popularity was classified as popular.
We found that typescript-transform-paths demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.