{"id":30955986,"url":"https://github.com/baranwang/rsbuild-plugin-protobufjs","last_synced_at":"2025-09-18T01:51:30.489Z","repository":{"id":312964773,"uuid":"1049477108","full_name":"baranwang/rsbuild-plugin-protobufjs","owner":"baranwang","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-03T03:33:29.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-11T13:19:56.502Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baranwang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-03T03:27:11.000Z","updated_at":"2025-09-10T05:25:20.000Z","dependencies_parsed_at":"2025-09-03T05:27:18.325Z","dependency_job_id":"bd42477f-b32b-4e00-ace6-7add5a6ac082","html_url":"https://github.com/baranwang/rsbuild-plugin-protobufjs","commit_stats":null,"previous_names":["baranwang/rsbuild-plugin-protobufjs"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/baranwang/rsbuild-plugin-protobufjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baranwang%2Frsbuild-plugin-protobufjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baranwang%2Frsbuild-plugin-protobufjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baranwang%2Frsbuild-plugin-protobufjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baranwang%2Frsbuild-plugin-protobufjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baranwang","download_url":"https://codeload.github.com/baranwang/rsbuild-plugin-protobufjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baranwang%2Frsbuild-plugin-protobufjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275696214,"owners_count":25511351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-11T12:02:31.912Z","updated_at":"2025-09-18T01:51:30.454Z","avatar_url":"https://github.com/baranwang.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Rsbuild Plugins"],"readme":"# rsbuild-plugin-protobufjs\n\n[English](README.md) | [中文](README.zh.md)\n\nAn Rsbuild plugin that integrates `protobufjs`. It compiles `.proto` files into JavaScript modules that run in browsers or Node.js, and can optionally generate TypeScript declaration files (`.d.ts`).\n\n- **What it does**: Automatically matches and transforms `.proto` files\n- **Built-in cache**: Uses Rsbuild `cachePath` and writes intermediates under `protobufjs`\n- **Configurable target**: Passes `--target` to `protobufjs-cli` (default `static-module`)\n- **Type output**: Generates `.d.ts` by default for better TS DX\n\n## Installation\n\n```bash\npnpm add -D rsbuild-plugin-protobufjs\n# or\nnpm i -D rsbuild-plugin-protobufjs\n# or\nyarn add -D rsbuild-plugin-protobufjs\n```\n\n- **peerDependencies**: `protobufjs` (install it in your project)\n- **dependencies**: The plugin uses `protobufjs-cli` internally to run `pbjs`/`pbts`\n\n## Quick Start\n\nAdd the plugin in your Rsbuild configuration:\n\n```ts\n// rsbuild.config.ts\nimport { defineConfig } from '@rsbuild/core';\nimport { protobufjsPlugin } from 'rsbuild-plugin-protobufjs';\n\nexport default defineConfig({\n  plugins: [\n    protobufjsPlugin({\n      // optional, see \"Options\" below\n    }),\n  ],\n});\n```\n\nNow import `.proto` files directly in your source code:\n\n```ts\nimport client from './client.proto';\n\n// With target=static-module (default), the imported object exposes static encode/decode APIs\nconsole.log(client);\n```\n\nDuring build or dev, the plugin will:\n- Use `pbjs` to compile `.proto` into a JS module, emitted into Rsbuild's cache directory under `protobufjs`.\n- If `dts` is enabled (default true), run `pbts` to emit `client.proto.d.ts` next to the source `.proto` file.\n\n## Options\n\nThe plugin exports `protobufjsPlugin(options?: Options)`.\n\n```ts\ninterface Options {\n  /**\n   * Files to include. Same as Rspack RuleSetCondition.\n   * @default /\\.proto$/\n   */\n  test?: import('@rsbuild/core').Rspack.RuleSetCondition;\n\n  /**\n   * Value passed to protobufjs-cli `--target`.\n   * Common values: 'static-module' (default), 'json-module', 'proto2', etc.\n   * @default 'static-module'\n   */\n  target?: string;\n\n  /**\n   * Whether to generate `.d.ts` for each `.proto`.\n   * @default true\n   */\n  dts?: boolean;\n}\n```\n\n- **test**: Which files to transform. Defaults to all `.proto` files.\n- **target**: Forwarded directly to `pbjs --target`. `static-module` is recommended for most applications.\n- **dts**: Whether to call `pbts` to emit a sibling `.d.ts` file next to the source.\n\n## Example\n\n```ts\n// rsbuild.config.ts\nimport { defineConfig } from '@rsbuild/core';\nimport { protobufjsPlugin } from 'rsbuild-plugin-protobufjs';\n\nexport default defineConfig({\n  plugins: [\n    protobufjsPlugin({\n      test: /\\.proto$/,           // only process .proto files\n      target: 'static-module',     // generate static module\n      dts: true,                   // generate type declarations\n    }),\n  ],\n});\n```\n\nProject code:\n\n```ts\n// src/index.ts\nimport client from './client.proto';\n\n// Use encode/decode APIs as needed\n// Actual exports depend on the chosen target = static-module\nconsole.log(client);\n```\n\nThe declaration file will be emitted next to the source, e.g., `src/client.proto.d.ts`.\n\n## FAQ\n\n- **Q: Do I need both protobufjs and protobufjs-cli installed?**\n  - A: Yes. `protobufjs` is a peer dependency you install in your project; the plugin depends on `protobufjs-cli` for compilation.\n\n- **Q: Where are intermediate outputs written?**\n  - A: Under Rsbuild's cache directory, e.g., `node_modules/.cache/rsbuild/\u003chash\u003e/protobufjs/`. This is an implementation detail; the final code is returned to Rsbuild's pipeline.\n\n- **Q: Can I emit JS without `.d.ts`?**\n  - A: Yes. Set `dts: false`.\n\n- **Q: How do I change pbjs output style?**\n  - A: Use `target` to pass a value supported by `pbjs --target`, such as `json-module`. Different targets produce different module shapes; see protobufjs-cli documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaranwang%2Frsbuild-plugin-protobufjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaranwang%2Frsbuild-plugin-protobufjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaranwang%2Frsbuild-plugin-protobufjs/lists"}