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.
Common errors
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
Warnings
gotcha Proto file imports only export a default object; named imports will be undefined. ↓
fix Use default import: import messages from './messages.proto'
Install
npm install rollup-plugin-protobuf yarn add rollup-plugin-protobuf pnpm add rollup-plugin-protobuf Imports
- default wrong
const protobuf = require('rollup-plugin-protobuf')correctimport protobuf from 'rollup-plugin-protobuf' - plugin usage wrong
plugins: [ protobuf.default({ convertFieldsToCamelCase: true }) ]correctplugins: [ protobuf({ convertFieldsToCamelCase: true }) ] - import messages wrong
import { messages } from './messages.proto'correctimport messages from './messages.proto'
Quickstart
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();