JSPM

  • Created
  • Published
  • Downloads 513942
  • Score
    100M100P100Q210358F
  • License Apache-2.0

Protocol Buffers code generator for ECMAScript

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@bufbuild/protoc-gen-es) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @bufbuild/protoc-gen-es

    This package provides the code generator plugin protoc-gen-es. The code it generates depends on @bufbuild/protobuf.

    Protocol Buffers for ECMAScript

    A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.

    For example, the following definition:

    message Person {
      string name = 1;
      int32 id = 2;  // Unique ID number for this person.
      string email = 3;
    }

    Is compiled to an ECMAScript class that can be used like this:

    let pete = new Person({
      name: "pete",
      id: 123
    });
    
    let bytes = pete.toBinary();
    pete = Person.fromBinary(bytes);
    pete = Person.fromJsonString('{"name": "pete", "id": 123}');

    Learn more at github.com/bufbuild/protobuf-es.

    Installation

    With npm

    npm install @bufbuild/protoc-gen-es

    This will install the code generator plugin in node_modules/.bin/protoc-gen-es. Note that npm does not add the executable to your $PATH. You can do so with:

    PATH=$PATH:$(pwd)/node_modules/.bin

    With yarn

    yarn add @bufbuild/protoc-gen-es

    Note that yarn v2 does not use a node_modules directory anymore. To find the path where yarn stores the executable, run yarn bin protoc-gen-es (it is "unplugged" automatically).

    You can always confirm successful installation with:

    protoc-gen-es --version

    Plugin options

    target

    This option controls whether the plugin generates JavaScript, TypeScript, or TypeScript declaration files.

    Possible values:

    • target=js - generates a _pb.js file for every .proto input file.
    • target=ts - generates a _pb.ts file for every .proto input file.
    • target=dts - generates a _pb.d.ts file for every .proto input file.

    Multiple values can be given by separating them with +, for example target=js+dts.

    By default, we generate JavaScript and TypeScript declaration files, which produces the smallest code size. If you prefer to generate TypeScript, use target=ts.