https://github.com/tiny-md/esbuild-plugin-peggy
🔌 Seamlessly load .pegjs or .peggy grammar files in your esbuild pipeline
https://github.com/tiny-md/esbuild-plugin-peggy
Last synced: 12 months ago
JSON representation
🔌 Seamlessly load .pegjs or .peggy grammar files in your esbuild pipeline
- Host: GitHub
- URL: https://github.com/tiny-md/esbuild-plugin-peggy
- Owner: tiny-md
- License: mpl-2.0
- Created: 2025-03-22T07:58:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-06T01:57:05.000Z (12 months ago)
- Last Synced: 2025-04-06T02:33:44.207Z (12 months ago)
- Language: TypeScript
- Size: 364 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Esbuild Plugin Peggy 
[](https://github.com/tiny-md/esbuild-plugin-peggy/actions/workflows/test.yml)
[](https://codeclimate.com/github/tiny-md/esbuild-plugin-peggy/maintainability)
[](https://codecov.io/gh/tiny-md/esbuild-plugin-peggy)
[](https://www.npmjs.com/package/esbuild-plugin-peggy)
[](https://www.npmjs.com/package/esbuild-plugin-peggy)
[](https://bundlephobia.com/package/esbuild-plugin-peggy)
[](https://gitpod.io/from-referrer/)
> 🔌 Seamlessly load `.pegjs` or `.peggy` grammar files directly into your esbuild pipeline
---
## ✨ Features
- 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
---
## 📦 Installation
```bash
pnpm add esbuild-plugin-peggy
```
**_or_**
```bash
npm install esbuild-plugin-peggy
```
**_or_**
```bash
yarn add esbuild-plugin-peggy
```
---
## 🚀 Usage
```ts
// 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:
```ts
import parser from "./grammar.pegjs";
const result = parser.parse("your input here");
```
---
## ⚙️ Plugin Options
You can pass either a global config or a list of per-file configs using `ParserBuildOptions` from [peggy](https://github.com/peggyjs/peggy).
### Global options
```ts
peggyPlugin({
allowedStartRules: ["Expression"],
});
```
### Per-file options
```ts
peggyPlugin([
{
pathPattern: /calculator\.pegjs$/,
options: { allowedStartRules: ["Calc"] },
},
]);
```
---
## 📁 Supported File Types
- `.pegjs`
- `.peggy`
---
## 🛠 Example
```ts
import parser from "./math.pegjs";
console.log(parser.parse("2 + 2")); // 4
```
---
## ✅ Why Use This?
- 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.
---
## 📜 License
Licensed under the **MPL-2.0** license.
© [Mayank Chaudhari](https://github.com/mayank1513)
---
>
> 📚 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