Skip to content

Commit

Permalink
Bundle both cjs and esm for api package (#129)
Browse files Browse the repository at this point in the history
* output both esm and cjs

* changeset
  • Loading branch information
taranvohra authored Mar 15, 2023
1 parent 0e25abc commit 5c68046
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-crabs-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/api': minor
---

Output both esm and cjs for @gitbook/api
4 changes: 3 additions & 1 deletion packages/api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ swagger-typescript-api --path ./spec/openapi.yaml --output ./src/ --name client.
swagger-cli bundle ./spec/openapi.yaml --outfile ./spec/openapi.json --type json

# Then we build the JS files
echo "Bundling library from code..."
echo "Bundling CJS format from code..."
esbuild ./src/index.ts --bundle --platform=node --format=cjs --outfile=./dist/index.cjs --log-level=warning
echo "Bundling ESM format from code..."
esbuild ./src/index.ts --bundle --platform=node --format=esm --outfile=./dist/index.js --log-level=warning

# Finally we build the TypeScript declaration files
Expand Down
14 changes: 12 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@gitbook/api",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"version": "0.2.2",
"sideEffects": false,
"files": [
Expand All @@ -29,5 +30,14 @@
"build": "./build.sh",
"lint": "eslint ./src/**/*.ts",
"typecheck": "tsc --noEmit"
},
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./spec/openapi.json": "./spec/openapi.json",
"./spec/openapi.yaml": "./spec/openapi.yaml"
}
}

0 comments on commit 5c68046

Please sign in to comment.