π Seamlessly load
.pegjs
or.peggy
grammar files directly into your esbuild pipeline
- Compile
.pegjs
/.peggy
files as ES modules with zero config - Fully compatible with both JavaScript and TypeScript
- No Node.js-only dependencies get into your codebase β frontend safe!
- Supports custom parser options and per-file overrides
- Simple, fast, and modern integration with esbuild
pnpm add esbuild-plugin-peggy
or
npm install esbuild-plugin-peggy
or
yarn add esbuild-plugin-peggy
// esbuild.config.ts
import { build } from "esbuild";
import { peggyPlugin } from "esbuild-plugin-peggy";
build({
entryPoints: ["src/index.ts"],
bundle: true,
outfile: "dist/bundle.js",
plugins: [peggyPlugin()],
});
Then in your source code:
import parser from "./grammar.pegjs";
const result = parser.parse("your input here");
You can pass either a global config or a list of per-file configs using ParserBuildOptions
from peggy.
peggyPlugin({
allowedStartRules: ["Expression"],
});
peggyPlugin([
{
pathPattern: /calculator\.pegjs$/,
options: { allowedStartRules: ["Calc"] },
},
]);
.pegjs
.peggy
import parser from "./math.pegjs";
console.log(parser.parse("2 + 2")); // 4
- Skip manual parser builds β just import and use
- Compatible with modern tooling and frameworks
- Great for in-browser parsing and visual tooling
- Keeps frontend builds clean of Node-only deps
Star this [repository](https://github.com/tiny-md/esbuild-plugin-peggy) and share it with friends.
Licensed under the MPL-2.0 license. Β© Mayank Chaudhari
π Enroll in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsor](https://github.com/sponsors/mayank1513) our work.
Made with π by Mayank Kumar Chaudhari