diff --git a/.gitignore b/.gitignore index 23cfa27..5d0a031 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ lib .nyc_output coverage @types +dist diff --git a/esbuild.js b/esbuild.js new file mode 100644 index 0000000..b8f25c1 --- /dev/null +++ b/esbuild.js @@ -0,0 +1,23 @@ +const { build } = require("esbuild"); +const glob = require("tiny-glob"); + +const watch = process.argv.at(-1) === "--watch"; + +(async () => { + let entryPoints = Object.fromEntries( + (await glob("./src/**/*.ts")).map((e) => [ + e.replace(/\.ts$/, ""), + e, + ]) + ); + build({ + entryPoints, + sourcemap: true, + outdir: "./dist", + logLevel: "info", + platform: "node", + watch, + target: "node16", + format: "cjs", + }); +})(); \ No newline at end of file diff --git a/package.json b/package.json index 0944595..faf88d8 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,11 @@ "description": "module template", "main": "lib/index.js", "scripts": { + "build": "node ./esbuild.js", + "prepare": "rm -rf @types && npm run typecheck && npm run build-declarations && npm run build", "test": "mocha", - "build": "tsc", - "prepare": "npm run build", + "build-declarations": "tsc --emitDeclarationOnly", + "typecheck": "tsc --noemit", "clean-coverage": "rm -rf coverage .nyc_output .xunit", "coverage": "npm run clean-coverage && nyc mocha", "test-reports": "npm run clean-coverage && nyc --reporter clover mocha --reporter xunit --reporter-option output=.xunit", @@ -29,7 +31,9 @@ "prettier": "^2.8.7", "source-map-support": "^0.5.21", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "typescript": "^5.0.4", + "esbuild": "^0.14.10", + "tiny-glob": "^0.2.9" }, "types": "./@types/index.d.ts" }