From 1d2a199114dbe60dc70a4055a9220c02a6071872 Mon Sep 17 00:00:00 2001 From: NielsJPeschel Date: Wed, 3 Apr 2024 15:58:24 -0400 Subject: [PATCH] feat: dual build to emit both commonJS and ESM to maximize compatibility --- package.json | 19 ++++--------------- tsconfig.es5.json | 28 ++++++++++++++++++++++++++++ tsconfig.json | 14 +++++++------- 3 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 tsconfig.es5.json diff --git a/package.json b/package.json index 1ff964e..9344d93 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,14 @@ { "name": "@optum/react-hooks", - "version": "1.0.2-next.1", + "version": "1.0.2-next.2", "description": "A reusable set of React hooks", "repository": "https://github.com/Optum/react-hooks", "license": "Apache 2.0", + "main": "build/lib/es5/index.js", + "module": "build/lib/es6/index.js", "sideEffects": false, "scripts": { - "build": "tsc --project tsconfig.json", + "build": "rm -rf build/lib && tsc && tsc --build tsconfig.es5.json", "prepack": "yarn build" }, "files": [ @@ -36,19 +38,6 @@ "dependencies": { "tslib": "^2.3.1" }, - "exports": { - ".": { - "require": { - "types": "./build/types/cjs/index.d.ts", - "default": "./build/cjs/index.js" - }, - "types": "./build/types/cjs/index.d.ts", - "default": "./build/cjs/index.js" - } - }, - "publishConfig": { - "access": "public" - }, "stableVersion": "1.8.0-next.245", "packageManager": "yarn@3.6.1" } diff --git a/tsconfig.es5.json b/tsconfig.es5.json new file mode 100644 index 0000000..3899c6a --- /dev/null +++ b/tsconfig.es5.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "target": "ES5", + "lib": ["ES2020", "DOM"], + "declaration": true, + "outDir": "./build/lib/es5", + "moduleResolution":"Node", + "preserveSymlinks": true, + "rootDir": ".", + "sourceMap": true, + "strict": true, + "noImplicitReturns": true, + "importHelpers": true, + "noEmitHelpers": true, + "noUnusedLocals": true, + "jsx": "preserve", + "allowJs": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "isolatedModules": true + }, + "exclude": ["node_modules"], + "include": ["**/*.ts", "**/*.tsx"] + } + \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7990e6d..d9cff11 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,13 @@ { "compilerOptions": { - "module": "Node16", - "moduleResolution":"Node16", + "module": "ES6", + "target": "ES5", + "lib": ["ES2020", "DOM"], + "declaration": true, + "outDir": "./build/lib/es6", + "moduleResolution":"Node", "preserveSymlinks": true, "rootDir": ".", - "outDir": "build/cjs", - "declaration": true, - "declarationDir": "build/types/cjs", - "target": "ES6", "sourceMap": true, "strict": true, "noImplicitReturns": true, @@ -22,6 +22,6 @@ "resolveJsonModule": true, "isolatedModules": true }, - "exclude": ["node_modules"], + "exclude": ["node_modules", "!node_modules/@types"], "include": ["**/*.ts", "**/*.tsx"] }