Skip to content

Commit 4f56856

Browse files
authored
fix: export types and commonjs bundle (#821)
1 parent 1a5e2a7 commit 4f56856

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

build.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
;(async () => {
22
const child = require('child_process')
3-
const fs = require('fs')
43
const {build} = require('esbuild')
54

65
await build({
7-
outdir: 'dist',
6+
outfile: 'dist/index.mjs',
87
format: 'esm',
98
target: 'es6',
109
bundle: true,
1110
external: ['@testing-library/dom'],
1211
entryPoints: ['src/index.ts'],
1312
})
1413

15-
fs.writeFileSync(
16-
'dist/package.json',
17-
JSON.stringify({
18-
type: 'module',
19-
}),
20-
)
14+
await build({
15+
outfile: 'dist/index.cjs',
16+
format: 'cjs',
17+
target: 'node12',
18+
bundle: true,
19+
external: ['@testing-library/dom'],
20+
entryPoints: ['src/index.ts'],
21+
})
2122

2223
child.execSync('yarn tsc -p tsconfig.build.json')
2324
})()

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@
2525
"files": [
2626
"dist"
2727
],
28-
"main": "./dist/index.js",
29-
"exports": "./dist/index.js",
28+
"main": "./dist/index.cjs",
29+
"module": "./dist/index.mjs",
30+
"exports": {
31+
".": {
32+
"require": "./dist/index.cjs",
33+
"default": "./dist/index.mjs"
34+
}
35+
},
36+
"types": "./dist/types/index.d.ts",
3037
"scripts": {
3138
"build": "node build.js",
3239
"lint": "kcd-scripts lint",

tsconfig.build.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
"extends": "./tsconfig.json",
33
"include": ["./src"],
44
"compilerOptions": {
5-
"outFile": "dist/index.d.ts",
5+
"outDir": "dist/types",
66
"noEmit": false,
77
"declaration": true,
8-
"emitDeclarationOnly": true,
9-
"isolatedModules": false
8+
"emitDeclarationOnly": true
109
}
1110
}

0 commit comments

Comments
 (0)