Zigar Rollup Plugin

raw JSON →
0.15.2 verified Mon Apr 27 auth: no javascript

A Rollup plugin (v0.15.2) that transpiles Zig source code into JavaScript/WASM, enabling Zig to be used as a dependency in web bundles. Released as part of the Zigar toolchain, it compiles Zig to WebAssembly and generates JS wrappers for seamless import in Rollup-based projects. Rapidly evolving (pre-1.0). Differentiates from Emscripten by targeting direct Zig compilation for bundlers.

error Error: Could not resolve './foo.zig' from 'src/bar.js'
cause Rollup cannot handle .zig files without the plugin or the plugin is not configured.
fix
Ensure the zigar plugin is included in the plugins array of your Rollup config.
error TypeError: zigar is not a function
cause Default import fails if package is not resolved correctly, possibly due to missing ESM support.
fix
Check that your project uses ESM (type: module in package.json) and Node.js >=14.
breaking Zigar v0.15 changed the plugin API: options object is no longer optional; zigar() now requires a config argument.
fix Pass an empty object explicitly: zigar({}).
breaking Node.js <14 are unsupported in v0.14+. ESM-only distribution removed CJS support.
fix Upgrade to Node.js 14+ and use ESM imports (i.e., package.json type: module or .mjs extension).
deprecated Support for Rollup <3 is deprecated; future versions will require Rollup 3+.
fix Update Rollup to 3.x or later.
gotcha Plugin only works with .zig files that export a main function. Exported functions must be public and have compatible signatures for WASM.
fix Ensure your Zig source exports a pub fn main() or pub fn exportedFunction() callable from JS.
npm install rollup-plugin-zigar
yarn add rollup-plugin-zigar
pnpm add rollup-plugin-zigar

Shows how to integrate the Zigar plugin into a Rollup config to transpile Zig imports (e.g., from .zig files) into JavaScript modules.

// rollup.config.js
import zigar from 'rollup-plugin-zigar';

export default {
  input: 'src/main.js',
  output: {
    dir: 'dist',
    format: 'esm',
  },
  plugins: [
    zigar({
      // optional: specify Zig compiler path
      // zigPath: '/usr/local/bin/zig',
    }),
  ],
};