Weevarv1.0.2

SWC plugin (Next.js)

Source-accurate prompts when your bundler is SWC.

Next.js, Bun, and a handful of custom build setups use SWC instead of Babel for JSX transforms. Weevar ships an SWC-based equivalent of the Vite plugin.


What it does#

The SWC plugin parses your TSX/JSX with @swc/core, walks the AST, and inserts data-wv-source="<file>:<line>:<col>" attributes onto every JSXOpeningElement. Same output as the Vite plugin, different parser.

If a data-wv-source is already present, it's kept. If parsing fails for any reason, the file is returned unchanged - Weevar fails open.


Install#

npm install weevar

@swc/core is an optional peer dependency. If you're already using Next.js or another SWC-based tool, you have it.


Use it directly#

import { transformJsxWithWeevarSourceSwc } from "weevar/swc";

const result = transformJsxWithWeevarSourceSwc(sourceCode, absoluteFilePath, projectCwd);
if (result) {
  // result.code has the injected attributes
}

The function returns { code: string } on success and null on parse failure.


With Next.js#

Next.js doesn't currently expose a public hook for arbitrary SWC transforms in app code. The recommended path while a first-class Next adapter is in development:

  1. Use a custom Webpack rule via next.config.js and the Webpack loader - it covers the same use case for Next users.
  2. Or, if you're already running a custom SWC pipeline (e.g. with swc-loader or a build script), call transformJsxWithWeevarSourceSwc from your own loader/visitor.

A first-class Next.js adapter is on the roadmap.