Registry / web-framework / vite-plugin-peggy-loader

vite-plugin-peggy-loader

JSON →
library2.0.1jsnpmunverified

Vite plugin that automatically compiles Peggy (PEG.js) grammar files (.pegjs, .peggy) into JavaScript parser modules during the build process. Version 2.0.1 supports Vite and accepts all standard Peggy options (cache, optimize, trace, dependencies, allowedStartRules). Released under MIT license. Alternatives include manual compilation or webpack's peggy-loader; this integrates seamlessly with Vite's plugin system and respects Vite's ESM transform.

npm install vite-plugin-peggy-loader
INSTALL
IMPORT
SIG · VITE-PLUGIN-PEGGY-
V
vite-plugin-peggy-loader
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import peggyLoader from 'vite-plugin-peggy-loader'
const peggyLoader = require('vite-plugin-peggy-loader')
ESM-only, no CommonJS export. Use dynamic import if needed.
peggyLoader (named)
import { peggyLoader } from 'vite-plugin-peggy-loader'
import peggyLoader from 'vite-plugin-peggy-loader'
Both default and named exports exist, but default is the common pattern per README.
PeggyOptions
import type { PeggyOptions } from 'vite-plugin-peggy-loader'
import { PeggyOptions } from 'vite-plugin-peggy-loader'
Type-only export for options object type, requires TypeScript.

Configures Vite to compile .pegjs files on import using Peggy with caching and speed optimization.

import { defineConfig } from 'vite'; import peggyLoader from 'vite-plugin-peggy-loader'; export default defineConfig({ plugins: [ peggyLoader({ cache: true, optimize: 'speed', trace: false }) ] });
Debug
Known issues
breakingVersion 2.0.0 dropped support for PEG.js < 1.2.0. Only Peggy ^1.2.0, ^3.0.2, and ^4.0.0 are supported as peer dependencies.
fix
Upgrade your grammar toolchain to Peggy >=1.2.0.
affects: >=2.0.0
deprecatedThe option `optimizeParser` was renamed to `optimize` in a previous version.
fix
Use the `optimize` option instead of `optimizeParser`.
affects: >=2.0.0
gotchaImporting `.pegjs` files yields a default export that is an object with a `parse` function, not the raw parser function. This differs from some other loaders.
fix
Use `import * as parser from './grammar.pegjs'` and call `parser.parse(input)`.
affects: >=1.0.0
gotchaThe plugin does not support `.peggy` file extension by default; only `.pegjs` is handled.
fix
Rename your files to `.pegjs` or modify the plugin's source to include `.peggy`.
affects: >=1.0.0
gotchaThe `dependencies` option requires that the parser's dependencies are available at runtime, but this plugin does not automatically include them in the bundle.
fix
Manually import the dependency modules in your code or configure Vite to handle them.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-peggy-loader' or its corresponding type declarations.
Missing npm install or types not included.
fix
Run `npm install vite-plugin-peggy-loader`. If using TypeScript, ensure `tsconfig.json` has `"moduleResolution": "node"` and `"esModuleInterop": true`.
Error: No known conditions for "./" specifier in "vite-plugin-peggy-loader" package
Using a Node.js version that does not support the `exports` field, or the import path is incorrect.
fix
Use Node >=12.20.0 or <14. It is an ESM package; use dynamic import if CommonJS is required.
TypeError: peggyLoader is not a function
Incorrect import: using named import `{ peggyLoader }` when default export is expected, or vice versa.
fix
Use `import peggyLoader from 'vite-plugin-peggy-loader'` (default import) or `import { peggyLoader } from 'vite-plugin-peggy-loader'` (named import) as available from version 2.0.1.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
peggyrequiredpeer dependency for grammar compilation
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vite-plugin-peggy-loader — npm install vite-plugin-peggy-loader · libregistry