This package has been deprecated

Author message:

this package has been renamed to "tsukuru"; there will be no new releases under the old name

ts-hybrid-esm-build
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

TypeScript Hybrid ESM Build

This package enables you to build a TypeScript package that's compatible with both CommonJS and ES Modules. It achieves this by:

  • Creating a normal build using your tsconfig.json
  • Creating another build with a modified configuration, overwriting some settings from yours to ensure ESM compatibility
  • Renaming all output files to .mjs and adjusting the imports accordingly with a TypeScript transformer

This is a heavy work in progress, use at your own risk!

Installing

yarn add --dev ts-hybrid-esm-build
# or 
npm install --save-dev ts-hybrid-esm-build

Configuration of package.json

Put this (or something similar) in your package.json:

{
    "main": "lib",
    "types": "lib",
    "module": "es",
    "exports": {
        ".": {
            "require": "./lib/index.js",
            "import": "./es/index.mjs"
        }
    },
    "scripts": {
        "build": "ts-hybrid-esm-build",
        "rebuild": "ts-hybrid-esm-build --clean"
    }
}

Assuming that your outDir is lib. The output directory of the ES Modules is currently hardcoded to be es.

CLI options

-c, --config-file

Specifies the path to your TypeScript configuration file (tsconfig.json). If none is given, ts-hybrid-esm-build will traverse the ancestors of your project directory until it finds a file named tsconfig.json.

--clean

Removes the output directories before building.

Readme

Keywords

Package Sidebar

Install

npm i ts-hybrid-esm-build

Weekly Downloads

1

Version

0.2.3

License

MIT

Unpacked Size

24 kB

Total Files

15

Last publish

Collaborators

  • d-fischer