ts-hybrid-esm-build

Enables you to build a TypeScript package that's compatible with both CommonJS and ES Modules

this package has been renamed to "tsukuru"; there will be no new releases under the old name
Last updated a month ago by d-fischer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ts-hybrid-esm-build 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.2.3                                ...           latest (a month ago)

5 Versions

  • 0.2.3 [deprecated]           ...           a month ago
  • 0.2.2 [deprecated]           ...           3 months ago
  • 0.2.1 [deprecated]           ...           3 months ago
  • 0.2.0 [deprecated]           ...           3 months ago
  • 0.1.0 [deprecated]           ...           3 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (10)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |