webpack-oxc-parsing-adapter
v0.1.0
Published
Webpack adapter that swaps the default acorn-based parsing pipeline for oxc-parser.
Downloads
121
Maintainers
Readme
webpack-oxc-parsing-adapter
A drop-in adapter that replaces webpack's default acorn parser with oxc-parser — a high-performance Rust-based JavaScript/TypeScript parser.
How it works
Webpack exposes a module.parser.javascript.parse hook that lets you supply a custom parse function. This adapter wraps oxc-parser and translates its output into the ESTree-compatible shape that webpack expects, including:
- Lazy
locresolution via binary search over line-start offsets (avoids computing locations for every node up front) - Semicolon position tracking for ASI (automatic semicolon insertion) detection
- Transparent proxying of nested AST nodes so that location data is only computed on demand
Requirements
- Node.js
>=18.0.0 - webpack
^5.0.0
Installation
npm install webpack-oxc-parsing-adapterwebpack is a peer dependency. If it is not already installed:
npm install --save-dev webpackUsage
In your webpack.config.js, import the adapter and pass it to module.parser.javascript.parse:
const oxcParse = require("webpack-oxc-parsing-adapter");
/** @type {import("webpack").Configuration} */
module.exports = {
module: {
parser: {
javascript: {
parse: oxcParse,
},
},
},
};That's all — webpack will now use oxc-parser for every JavaScript module in the build.
Example
A minimal working project lives in the example/ directory.
example/
src/
index.js # entry point
math.js
greet.js
webpack.config.js
package.jsonTo run it:
cd example
npm install
npm run buildThe compiled output is written to example/dist/.
API
The adapter exports a single function with the signature expected by webpack:
function oxcParse(sourceCode: string, options: ParseOptions): ParseResult| Parameter | Type | Description |
|--------------|----------------|------------------------------------------|
| sourceCode | string | The JavaScript/TypeScript source to parse |
| options | ParseOptions | Webpack parse options (sourceType, etc.) |
Returns a ParseResult object with ast, comments, and semicolons.
License
MIT @ Even Stensberg
