diff --git a/shared/build-shared.js b/shared/build-shared.js new file mode 100644 index 00000000..7ebd0665 --- /dev/null +++ b/shared/build-shared.js @@ -0,0 +1,28 @@ +import esbuild from "esbuild"; + +esbuild + .build({ + entryPoints: ["src/index.ts"], + bundle: true, + platform: "node", + sourcemap: true, + outdir: "dist", + format: "esm", + target: "esnext", + splitting: true, + outExtension: { ".js": ".esm.js" }, + }) + .catch(() => process.exit(1)); + +esbuild + .build({ + entryPoints: ["src/index.ts"], + bundle: true, + platform: "node", + sourcemap: true, + outdir: "dist", + format: "cjs", + target: "es2015", + outExtension: { ".js": ".cjs.js" }, + }) + .catch(() => process.exit(1)); diff --git a/shared/package.json b/shared/package.json index 37e0ed87..e5a26673 100644 --- a/shared/package.json +++ b/shared/package.json @@ -2,14 +2,16 @@ "name": "@editor-extensions/shared", "version": "0.0.1", "private": true, - "main": "./dist/index.js", + "main": "./dist/index.cjs.js", + "type": "module", + "module": "./dist/index.esm.js", "types": "./dist/index.d.ts", "scripts": { "clean": "rimraf dist", "lint": "eslint .", "lint:fix": "eslint --fix .", "prebuild": "npm run clean", - "build": "tsc --build", + "build": "node build-shared.js && tsc --emitDeclarationOnly", "dev": "tsc --build --watch --preserveWatchOutput" }, "lint-staged": { diff --git a/shared/tsconfig.json b/shared/tsconfig.json index c21e4bd7..06b4a517 100644 --- a/shared/tsconfig.json +++ b/shared/tsconfig.json @@ -7,7 +7,9 @@ "declaration": true, "declarationMap": true, "sourceMap": true, - "tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo" + "tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo", + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["src/**/*.ts"], "exclude": ["dist", "node_modules"]