Skip to content

Commit

Permalink
add esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Jan 13, 2025
1 parent 5c51673 commit 5f71a08
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/t2006.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

// eslint-disable-next-line node/no-unpublished-import
import "../src/index.js";
import "../dist/index.js";
37 changes: 37 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { build } from "esbuild";
import fs from "node:fs";
import path from "node:path";

const getNodeModules = () => {
const nodeModulesPath = path.resolve(import.meta.dirname, "node_modules");
if (!fs.existsSync(nodeModulesPath)) {
return [];
}

return fs.readdirSync(nodeModulesPath).filter((module) => {
return !module.startsWith(".");
});
};

const ESBUILD_NAME = "NPM Bundle";
const OUT_FILE = "dist/index.js";

const nodeModules = getNodeModules();

const buildOptions = {
bundle: true,
entryPoints: ["src/index.js"],
external: nodeModules,
format: "esm",
outfile: OUT_FILE,
platform: "node",
};

build(buildOptions)
.then(() => {
console.log(`${ESBUILD_NAME} has been built to ${OUT_FILE}`);
})
.catch((e) => {
console.error(`Error building ${ESBUILD_NAME}: ${e.message}`);
process.exit(1);
});
Loading

0 comments on commit 5f71a08

Please sign in to comment.