Skip to content

Commit

Permalink
Merge pull request #8 from mkayander/feature/5-build
Browse files Browse the repository at this point in the history
#5 Add bundler to output a working built module
  • Loading branch information
mkayander authored Nov 16, 2022
2 parents da0c5a3 + 7d950a6 commit 4208430
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules

.env.example
.env

/dist
37 changes: 37 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { execSync } from "child_process";
import rimraf from "rimraf";
import esbuild from "esbuild";

const indexEntry = "src/index.ts";

const mainOptions: esbuild.BuildOptions = {
entryPoints: [indexEntry],
bundle: true,
// outfile: "dist/index.js",
platform: "node",
target: "node14",
};

(async () => {
rimraf.sync("dist");

try {
await esbuild.build({
...mainOptions,
entryPoints: [indexEntry, "src/bin/easyenv.ts"],
format: "cjs",
outdir: "dist/lib",
});

await esbuild.build({
...mainOptions,
format: "esm",
outdir: "dist/esm",
});

execSync("tsc", { stdio: "inherit" });
} catch (e) {
console.error(e);
process.exit(1);
}
})();
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
"name": "@top-tools/easyenv",
"version": "1.2.0",
"description": "",
"main": "index.js",
"type": "module",
"bin": {
"easyenv": "./dist/bin/easyenv.js"
},
"main": "dist/lib/index.js",
"module": "dist/esm/index.js",
"typings": "dist/lib/index.d.ts",
"files": [
"dist"
],
"repository": "https://github.com/mkayander/easyenv",
"keywords": [],
"author": {
Expand All @@ -16,14 +23,19 @@
"access": "public"
},
"scripts": {
"build": "tsx build.ts",
"test": "echo \"Error: no test specified\" && exit 1",
"semantic-release": "semantic-release"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/node": "^18.11.9",
"@types/rimraf": "^3.0.2",
"esbuild": "^0.15.14",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.5",
"tsx": "^3.11.0",
"typescript": "^4.8.4"
Expand Down
Loading

0 comments on commit 4208430

Please sign in to comment.