webpack-grpc-web-loader
A webpack loader to load .proto files for grpc-web with effortless setup.
Last updated 5 months ago by foisonocean .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install webpack-grpc-web-loader 
SYNC missed versions from official npm registry.

Webpack GRPC Web Loader

Install

???? You don't have to install protoc or protoc-gen-grpc-web plugin in your environment, just use npm or yarn to install this webpack loader, and everything is done.

npm install --save-dev webpack-grpc-web-loader

Or

yarn add --dev webpack-grpc-web-loader

Getting Started

webpack.config.js

const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        test: /\.proto$/,
        use: [
          {
            loader: 'webpack-grpc-web-loader',
            options: {
              protoPath: path.resolve(__dirname, './src/protos'),
            },
          },
        ],
      },
    ],
  },
};

If you have multiple proto paths, you can pass an array to the option protoPath:

{
  loader: 'webpack-grpc-web-loader',
  options: {
    protoPath: [
      path.resolve(__dirname, './src/my-protos-1'),
      path.resolve(__dirname, './src/my-protos-2'),
    ],
  },
}

In your src

import helloWorldProto from './hello-world.proto';

const client = new helloWorldProto.HelloWorldClient('http://localhost:11101/grpc');
const helloRequest = new helloWorldProto.HelloRequest();
client.helloWorld(helloRequest, {}, (err, res) => {
  // handle error and response here
});

Options

Option Name Type Required Default Value Description
protoPath string | string[] true N/A Same as --proto_path (-I) in protoc

Current Tags

  • 0.1.6                                ...           latest (5 months ago)

7 Versions

  • 0.1.6                                ...           5 months ago
  • 0.1.5                                ...           5 months ago
  • 0.1.4                                ...           6 months ago
  • 0.1.3                                ...           6 months ago
  • 0.1.2                                ...           7 months ago
  • 0.1.1                                ...           7 months ago
  • 0.1.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 0
Last Month 1
Dependencies (8)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |