Skip to content

Webpack loader to translate .proto definitions to ProtoBuf.js modules

License

Notifications You must be signed in to change notification settings

PermissionData/protobufjs-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status semantic-release

protobufjs-loader

Webpack loader to translate protobuf definitions to ProtoBuf.js modules. Equivalent to running your definitions through the pbjs CLI.

This allows you to use the light or minimal ProtoBuf.js distributions without an explicit compile step in your build pipeline.

Install

npm install --save-dev protobufjs-loader-webpack4

Usage

// webpack.config.js

module.exports = {
    ...
    module: {
        rules: [{
            test: /\.proto$/,
            use: {
              loader: 'protobufjs-loader',
              options: {
                /* controls the "target" flag to pbjs - true for
                 * json-module, false for static-module.
                 * default: false
                 */
                json: true,
                
                /* import paths provided to pbjs.
                 * default: webpack import paths (i.e. config.resolve.modules)
                 */
                paths: ['/path/to/definitions'],
                
                /* additional command line arguments passed to
                 * pbjs, see https://github.com/dcodeIO/ProtoBuf.js/#pbjs-for-javascript
                 * for a list of what's available.
                 * default: []
                 */
                pbjsArgs: ['--no-encode']
              }
            }
        }]
    }
};
// myModule.js

/* replaces e.g.:
 * 
 *   const protobuf = require('protobufjs/light');
 *   const jsonDescriptor = require('json!my/compiled/protobuf.js');
 *   const Root = protobuf.Root.fromJSON(jsonDescriptor);
 */
const Root = require('my/protobuf.proto');

About

Webpack loader to translate .proto definitions to ProtoBuf.js modules

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%