rollup-plugin-protobuf

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

A Rollup plugin that converts .proto files into JavaScript modules using protobuf.js. Version 0.1.1 (stable, no recent updates). It integrates protobuf compilation into the Rollup build pipeline, allowing direct import of .proto files. Differentiates by being Rollup-specific and supporting options like convertFieldsToCamelCase. No known alternatives for Rollup + protobuf.

error Error: Cannot find module 'rollup-plugin-protobuf'
cause Package not installed or missing from node_modules.
fix
Run: npm install --save-dev rollup-plugin-protobuf
gotcha Proto file imports only export a default object; named imports will be undefined.
fix Use default import: import messages from './messages.proto'
npm install rollup-plugin-protobuf
yarn add rollup-plugin-protobuf
pnpm add rollup-plugin-protobuf

Shows how to configure the plugin with convertFieldsToCamelCase option and import a .proto file.

import { rollup } from 'rollup';
import protobuf from 'rollup-plugin-protobuf';

async function build() {
  const bundle = await rollup({
    input: 'src/main.js',
    plugins: [
      protobuf({ convertFieldsToCamelCase: true })
    ]
  });
  await bundle.write({ file: 'dist/bundle.js', format: 'esm' });
}

build();