diff --git a/package.json b/package.json index d124e68..8dfb880 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "scripts": { "test": "./scripts/test", "build": "./scripts/build", + "build:browser": "./scripts/build-browser.sh", "prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1", "format": "./scripts/format", - "prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build && ./scripts/utils/git-swap.sh; fi", "tsn": "ts-node -r tsconfig-paths/register", "lint": "./scripts/lint", "fix": "./scripts/format" @@ -29,11 +29,11 @@ "@swc/core": "^1.3.102", "@swc/jest": "^0.2.29", "@types/jest": "^29.4.0", - "@types/ws": "^8.5.13", "@types/node": "^20.17.6", - "typescript-eslint": "8.31.1", + "@types/ws": "^8.5.13", "@typescript-eslint/eslint-plugin": "8.31.1", "@typescript-eslint/parser": "8.31.1", + "esbuild": "^0.25.5", "eslint": "^9.20.1", "eslint-plugin-prettier": "^5.4.1", "eslint-plugin-unused-imports": "^4.1.4", @@ -48,6 +48,7 @@ "tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.8/tsc-multi.tgz", "tsconfig-paths": "^4.0.0", "typescript": "5.8.3", + "typescript-eslint": "8.31.1", "ws": "^8.18.0", "zod": "^3.23.8" }, diff --git a/scripts/build-browser.sh b/scripts/build-browser.sh new file mode 100755 index 0000000..aeca43e --- /dev/null +++ b/scripts/build-browser.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -exuo pipefail + +# Base directory +cd "$(dirname "$0")/.." + +# Input: dist/index.mjs is the ESM build from `tsc-multi` +INPUT="dist/index.mjs" + +# Output (ESM) +esbuild "$INPUT" \ + --bundle \ + --platform=browser \ + --target=es2020 \ + --format=esm \ + --outfile=dist/openai-dev.mjs + +# Minified version +esbuild "$INPUT" \ + --bundle \ + --platform=browser \ + --target=es2020 \ + --format=esm \ + --minify \ + --outfile=dist/openai.mjs