Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: bundling generated files as npm package #173

Closed
jvmlet opened this issue May 6, 2019 · 2 comments
Closed

Question: bundling generated files as npm package #173

jvmlet opened this issue May 6, 2019 · 2 comments

Comments

@jvmlet
Copy link

jvmlet commented May 6, 2019

Hello
What would be the recommended approach to package all generated js files as npm package while exporting all modules.
Thanks

@jonny-improbable
Copy link
Contributor

jonny-improbable commented May 15, 2019

Hi @jvmlet, sorry for the slow response.

You can package up the generated output in as an npm module by adding the following package.json to in the root directory of the generated output (ie: the proto folder), ensuring that you declare dependencies on google-protobuf and its typedefs:

{
  "name": "my-protos",
  "version": "1.0.0",
  "description": "",
  "dependencies": {
    "@types/google-protobuf": "^3.2.7",
    "google-protobuf": "^3.8.0-rc.1"
  }
}

Following an npm install, your directory structure should look something like this:

├── node_modules
├── orphan_pb.d.ts
├── orphan_pb.js
├── orphan_pb_service.d.ts
├── orphan_pb_service.js
├── package-lock.json
└── package.json

Now, in the consumer package, you will be able to declare a dependency on the my-protos package as you would any other module and import using the following syntax:

import { OrphanStreamRequest } from 'my-protos/orphan_pb';

Please let me know if you have any followup questions.

@samlevin
Copy link

is this supported when generating PBs/RPCs for multiple protos in different/nested directories?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants