Skip to content

Commit

Permalink
Add esbuild script for esm / commonjs shared builds
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Jan 13, 2025
1 parent 998abb6 commit be715f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
28 changes: 28 additions & 0 deletions shared/build-shared.js
Original file line number Diff line number Diff line change
@@ -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));
6 changes: 4 additions & 2 deletions shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit be715f2

Please sign in to comment.