diff --git a/package.json b/package.json index 6db9d19..7a21aee 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,23 @@ "name": "quaire", "description": "a framework-agnostic library to create user-flows, surveys, and questionnaires", "version": "0.1.0", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + } }, "./package.json": "./package.json" }, + "sideEffects": false, "files": [ "dist" ], @@ -31,7 +39,7 @@ "url": "git+https://github.com/devCrossNet/quaire.git" }, "scripts": { - "compile": "tsc", + "compile": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/write-dist-package-files.mjs", "prebuild": "npm run clean", "build": "npm run compile", "clean": "rimraf ./dist ./coverage", diff --git a/scripts/write-dist-package-files.mjs b/scripts/write-dist-package-files.mjs new file mode 100644 index 0000000..b948af7 --- /dev/null +++ b/scripts/write-dist-package-files.mjs @@ -0,0 +1,5 @@ +import { writeFileSync } from 'node:fs'; + +// tells Node.js how to load the files in each build folder +writeFileSync('dist/esm/package.json', `${JSON.stringify({ type: 'module' }, null, 2)}\n`); +writeFileSync('dist/cjs/package.json', `${JSON.stringify({ type: 'commonjs' }, null, 2)}\n`); diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..8ab4792 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "./dist/cjs" + } +} diff --git a/tsconfig.json b/tsconfig.json index 7bcd72b..80293b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,12 @@ { "compilerOptions": { + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "Bundler", "declaration": true, - "module": "commonjs", - "target": "ES2019", + "strict": true, "rootDir": "./src", - "outDir": "./dist", - "strict": true + "outDir": "./dist/esm" }, "include": ["./src"], "exclude": ["/node_modules/", "dist", "**/*.spec.ts"]