|
1 | 1 | # Protoc Tools gRPC Web Plugin
|
2 |
| -**Protoc gRPC web generator plugin for @accility/protoc-tools ([NPM](https://npmjs.com/package/accility/protoc-tools) | [GitHub](https://github.com/accility/protoc-tools))** |
| 2 | +**This [accility/protoc-tools](https://github.com/accility/protoc-tools) plugin uses [protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases) to generate the gRPC Web files.** The protoc-gen-grpc-web binary can be downloaded and used as-is, however this have some implications, that mainly being: adding the binary to path and installation. This plugin solves both of theese issues. |
3 | 3 |
|
4 |
| -This package downloads and utilizes the [gRPC Web](https://github.com/grpc/grpc-web) ([protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases)) plugin from the [gRPC](https://github.com/grpc) project on post-install. |
| 4 | +For a more in-depth documentation, visit https://github.com/grpc/grpc-web. |
5 | 5 |
|
6 |
| -[protoc-gen-grpc-web](https://github.com/grpc/grpc-web/releases) is a plugin and can be used with [@accility/protoc-tools](https://github.com/accility/protoc-tools) directly. But protoc-gen-grpc-web is a binary and needs to be installed for respectively operating system, which this plugin does on post-install **and** needs to be executed in PATH, which this plugin adds the binary directory to the process enviroment PATH variable. |
7 |
| - |
8 |
| -## Usage |
| 6 | +``` |
| 7 | +npm install --save-dev @accility/protoc-tools protoc-tools-grpc-web-plugin |
| 8 | +``` |
9 | 9 |
|
10 | 10 | ```javascript
|
11 | 11 | import * as tools from '@accility/protoc-tools'
|
12 |
| -import * as gRPCWeb from '../dist/plugin' |
13 |
| - |
14 |
| -// OR |
15 |
| - |
16 |
| -const tools = require('@accility/protoc-tools') |
17 |
| -const gRPCWeb = require('../dist/plugin') |
| 12 | +import * as grpcweb from 'protoc-tools-grpc-web-plugin' |
18 | 13 |
|
19 | 14 | tools.protoc({
|
20 | 15 | ...
|
21 | 16 | outOptions: [
|
22 | 17 | tools.generators.js({
|
23 | 18 | outOptions: 'import_style=commonjs'
|
24 | 19 | }),
|
25 |
| - gRPCWeb({ |
26 |
| - module: 'commonjs', // 'closure' | 'commonjs' | 'commonjs+dts' | 'typescript' |
27 |
| - // mode: 'grpcwebtext' | 'grpcweb' |
| 20 | + grpcweb({ |
| 21 | + // required: 'closure' | 'commonjs' | 'commonjs+dts' | 'typescript' |
| 22 | + module: 'commonjs', |
| 23 | + |
| 24 | + // optional: 'grpcwebtext' | 'grpcweb' |
| 25 | + mode: 'grpcwebtext' |
28 | 26 | })
|
29 | 27 | ]
|
30 | 28 | })
|
31 | 29 | ```
|
32 |
| - |
33 |
| -### Module |
34 |
| -Import style (https://github.com/grpc/grpc-web#import-style) |
35 |
| - |
36 |
| -- `closure` - the default generated code has Closure `goog.require()` import style. |
37 |
| -- `commonjs` - the CommonJS style `require()` is also supported. |
38 |
| -- `commonjs+dts` - (experimental) in addition to above, a .d.ts typings file will also be generated for the protobufssages and service stub. |
39 |
| -- `typescript` - (experimental) the service stub will be generat |
40 |
| - |
41 |
| -### Mode |
42 |
| -Wire format mode (https://github.com/grpc/grpc-web#wire-format-mode) |
43 |
| - |
44 |
| -`grpcwebtext`: The default generated code sends the payload in the grpc-web-text format. |
45 |
| -- `Content-type: application/grpc-web-text` |
46 |
| -- Payload are base64-encoded. |
47 |
| -- Both unary and server streaming calls are supported. |
48 |
| - |
49 |
| -`grpcweb`: A binary protobuf format is also supported. |
50 |
| -- `Content-type: application/grpc-web+proto` |
51 |
| -- Payload are in the binary protobuf format. |
52 |
| -- Only unary calls are supported for now. |
0 commit comments