From 7a5b027c680bd53397f639a3e1cfd415d1b30bf3 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 25 Oct 2024 12:09:56 -0500 Subject: [PATCH] add support for bundling both esm and cjs versions --- package.json | 17 ++++++++++++++--- tsconfig.cjs.json | 8 ++++++++ tsconfig.esm.json | 8 ++++++++ tsconfig.json | 14 +++++++------- tsconfig.types.json | 8 ++++++++ 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json create mode 100644 tsconfig.types.json diff --git a/package.json b/package.json index 03cf5cb..7b61ab9 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,22 @@ "name": "@jwetzell/posistagenet", "version": "1.0.0", "description": "", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js", + "types": "./dist/types/index.d.ts" + } + }, "scripts": { "prebuild": "rimraf dist", - "build": "tsc", + "build": "npm run build:cjs && npm run build:esm && npm run build:types", + "build:cjs":"tsc -p tsconfig.cjs.json", + "build:esm":"tsc -p tsconfig.esm.json", + "build:types":"tsc -p tsconfig.types.json", "example:client": "node examples/psn_client.js", "example:server": "node examples/psn_server.js", "prepublishOnly": "npm run build" diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..265ef58 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "declaration": false, + "outDir": "./dist/cjs" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..547b0be --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "declaration": false, + "outDir": "./dist/esm" + } +} diff --git a/tsconfig.json b/tsconfig.json index 71e16d2..a5d4c1d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { "compilerOptions": { + "moduleResolution": "Node", + "lib": ["ESNext"], + "target": "ESNext", "esModuleInterop": true, - "module": "commonjs", - "target": "ES2020", - "declaration": true, - "rootDir": "./src", - "strict": true, - "outDir": "dist" + "isolatedModules": true, + "rootDir": "src/", + "strict": true }, - "exclude": ["node_modules", "dist", "examples"] + "include": ["src/"] } diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..2497e33 --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true, + "declaration": true, + "outDir": "./dist/types" + } +}