From 4f56856bfc64aa1fcc6ee8ab91050b61ee7c2e7e Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Fri, 31 Dec 2021 18:35:35 +0100 Subject: [PATCH] fix: export types and commonjs bundle (#821) --- build.js | 17 +++++++++-------- package.json | 11 +++++++++-- tsconfig.build.json | 5 ++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/build.js b/build.js index 92f03a40..426c71cb 100644 --- a/build.js +++ b/build.js @@ -1,10 +1,9 @@ ;(async () => { const child = require('child_process') - const fs = require('fs') const {build} = require('esbuild') await build({ - outdir: 'dist', + outfile: 'dist/index.mjs', format: 'esm', target: 'es6', bundle: true, @@ -12,12 +11,14 @@ entryPoints: ['src/index.ts'], }) - fs.writeFileSync( - 'dist/package.json', - JSON.stringify({ - type: 'module', - }), - ) + await build({ + outfile: 'dist/index.cjs', + format: 'cjs', + target: 'node12', + bundle: true, + external: ['@testing-library/dom'], + entryPoints: ['src/index.ts'], + }) child.execSync('yarn tsc -p tsconfig.build.json') })() diff --git a/package.json b/package.json index f976b054..44b6b20b 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,15 @@ "files": [ "dist" ], - "main": "./dist/index.js", - "exports": "./dist/index.js", + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "exports": { + ".": { + "require": "./dist/index.cjs", + "default": "./dist/index.mjs" + } + }, + "types": "./dist/types/index.d.ts", "scripts": { "build": "node build.js", "lint": "kcd-scripts lint", diff --git a/tsconfig.build.json b/tsconfig.build.json index 0836fd9a..0b90c4f4 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,10 +2,9 @@ "extends": "./tsconfig.json", "include": ["./src"], "compilerOptions": { - "outFile": "dist/index.d.ts", + "outDir": "dist/types", "noEmit": false, "declaration": true, - "emitDeclarationOnly": true, - "isolatedModules": false + "emitDeclarationOnly": true } }