Skip to content

Commit

Permalink
fix: export types and commonjs bundle (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche authored Dec 31, 2021
1 parent 1a5e2a7 commit 4f56856
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
17 changes: 9 additions & 8 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
;(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,
external: ['@testing-library/dom'],
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')
})()
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 4f56856

Please sign in to comment.