typescript-transformer-esm
v1.1.0
Published
Make import/export ESM compatible by appending .js (file) or /index.js (directory)
Downloads
1,279
Maintainers
Readme
typescript-transformer-esm
Inspired by
@zoltu/typescript-transformer-append-js-extension
and@nvandamme/typescript-transformer-append-js-extension
Make import
/export
ESM compatible by appending .js
(file) or /index.js
(directory).
Why? TypeScript's issues 783
and 16577
have been closed.
Example
Source (TypeScript):
import a from "./file";
import b from "./directory";
Compiled (JavaScript):
import a from "./file.js";
import b from "./directory/index.js";
Usage
Warning: Make sure
"module": "esnext"
is present intsconfig.json
Note: Compatible with
typescript-transform-paths
Install
npm install --save-dev typescript-transformer-esm
Install dependencies
ts-patch
npm install --save-dev ts-patch && npx ts-patch install -s
ttypescript
npm install --save-dev ttypescript
Update
tsconfig.json
{ "compilerOptions": { "module": "esnext", // ... "plugins": [ { "transform": "typescript-transformer-esm", "after": true } ] } }
Compile
ts-patch
npx tsc --build tsconfig.json
ttypescript
npx ttsc --build tsconfig.json
Contributing
I would love to see your contribution :heart:
See CONTRIBUTING guidelines.
License
This project is licensed under the MIT License.
See LICENSE file for details.