typescript-transform-extensions
Transforms imports to include the file extension of the resolved import, necessary for ES Modules.
This TypeScript plugin is helpful along with typescript-transform-paths. This plugin was inspired by typescript-transform-paths, thank you for all of your hard work!
ttypescript or ts-patch
Usable withInstall
npm:
npm i -D typescript-transform-extensions
yarn:
yarn add -D typescript-transform-extensions
Example Config
Add it to plugins in your tsconfig.json
Example output
- dest/
- path/
- to/
-import/
- file.js
- subdir/
- main.js
- src/
- path/
- to/
-import/
- file.ts
- subdir/
- main.ts
src/path/to/import/file.ts
src/subdir/main.ts
; sum22, 3;
Gets compiled to:
If
compilerOptions.module
is "CommonJS"
dest/subdir/main.js
var sum_1 = ;sum_1;
If
compilerOpions.module
is "ES2015", "ES2020", "ES6", or "ESNext"
dest/subdir/main.js
;;
Contributting
Contributions are welcome!
- make sure to format code with prettier:
npm run format