ts-dual-module
TypeScript icon, indicating that this package has built-in type declarations

0.6.3 • Public • Published

ts-dual-module

Easily build ts projects as dual packaged modules (cjs+esm)

The tool is designed to work on ESM packages (type: "module") and will build both ESM and commonjs versions of your code using typescript. The package.json exports is automatically updated to match your build.

A dual module project is usually storing the source files in a directoy like ./src`` and the generated files in a directory like ./dist`. The minimal layout of a projet is:

./dist
./src
package.json
tsconfig.json

The first time the build is done (or if you run npx tsmod init) you will be asked for the oputput directory name where the generated files will be stored.

You must create a ./tsconfig.json file in the project root, which will be used by the tool to as the base tsc configuration. If you don't have one just run npx tsmod init and it will create one for you.

If you need to customize the tsconfig.json file differently for esm or cjs you can create a specific files for each build: tsconfig.esm.json and tsconfig.cjs.esm hich will take precendence over tsconfig.json.

To start a build run: npx tsmod build. You can pass any additional tsc options you need.

Sub-paths exports

Also, sub-paths exports are supported (this is not working by default with commonjs builds because typescript is only handling subpath exports if moduleResolution >= Node16).

The tool is fxing this by mapping types using a typesVersions entry in the package.json

See:

To add an export path run: npx tsmod export mypath path/to/out/file.js

Package Sidebar

Install

npm i ts-dual-module

Weekly Downloads

88

Version

0.6.3

License

MIT

Unpacked Size

30.3 kB

Total Files

17

Last publish

Collaborators

  • bstefanescu