typescript-transformer-esm

1.1.0 • Public • Published

typescript-transformer-esm

ci

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 in tsconfig.json

Note: Compatible with typescript-transform-paths

  1. Install

    npm install --save-dev typescript-transformer-esm
  2. Install dependencies

    ts-patch or ttypescript

    • ts-patch

      npm install --save-dev ts-patch && npx ts-patch install -s
    • ttypescript

      npm install --save-dev ttypescript
  3. Update tsconfig.json

    {
      "compilerOptions": {
        "module": "esnext",
        // ...
        "plugins": [
          {
            "transform": "typescript-transformer-esm",
            "after": true
          }
        ]
      }
    }
  4. Compile

    • ts-patch

      npx tsc --build tsconfig.json
    • ttypescript

      npx ttsc --build tsconfig.json

Contributing

I would love to see your contribution ❤️

See CONTRIBUTING guidelines.

License

This project is licensed under the MIT License.
See LICENSE file for details.

Package Sidebar

Install

npm i typescript-transformer-esm

Weekly Downloads

42

Version

1.1.0

License

MIT

Unpacked Size

12.9 kB

Total Files

5

Last publish

Collaborators

  • carlocorradini