diff --git a/package.json b/package.json index cefc39fb5..70ddfce94 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,29 @@ "engines": { "node": ">=18" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "type": "module", + "exports": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/types/index.d.ts", "files": [ - "dist", - "lib" + "dist" ], "scripts": { "pretest": "npm run format && npm run build", - "test": "TEST_PORT=1234 TS_NODE_CACHE=0 mocha --exit", + "test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' TEST_PORT=1234 TS_NODE_CACHE=0 mocha --exit", "covtest": "TEST_PORT=1234 TS_NODE_CACHE=0 nyc mocha --exit", "prettier": "prettier \"{lib,test}/**/*.ts\"", "format": "npm run prettier -- --write", "format:check": "npm run prettier -- -l", "clean": "rm -rf dist/*", "prebuild": "npm run format:check && npm run clean", - "build": "tsc", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.esm.json", + "build": "npm run build:cjs && npm run build:esm", "docs": "vuepress dev docs", "docs:build": "vuepress build docs", "docs:deploy": "./scripts/deploy-docs.sh", diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 000000000..5fac85b33 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "ESNext", + "noImplicitAny": true, + "rootDirs": [ + "lib", + "test" + ], + "declaration": true, + "declarationDir": "./dist/types/", + }, + "include": [ + "lib/**/*.ts", + ] +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 000000000..197546446 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "./dist/cjs", + }, +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 000000000..fb6f63b8d --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "Bundler", + "esModuleInterop": true, + "outDir": "./dist/esm", + }, +} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 13fb10b99..000000000 --- a/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es2017", - "noImplicitAny": true, - "outDir": "dist", - "rootDirs": ["lib", "test"], - "declaration": true, - }, - "include": [ - "lib/**/*.ts", - ] -}