Permalink
Browse files

Breaking: Cleaned up library distributions, now is full / light / min…

…imal with proper browserify support for each
  • Loading branch information...
dcodeIO committed Jan 20, 2017
1 parent 28ddf75 commit 4bff9c356ef5c10b4aa34d1921a3b513e03dbb3d
Showing with 572 additions and 588 deletions.
  1. +17 −5 README.md
  2. +2 −2 cli/targets/static-module.js
  3. +1 −3 dist/README.md
  4. +31 −0 dist/light/README.md
  5. +206 −279 dist/{noparse → light}/protobuf.js
  6. +1 −0 dist/light/protobuf.js.map
  7. +9 −0 dist/light/protobuf.min.js
  8. BIN dist/light/protobuf.min.js.gz
  9. +1 −0 dist/light/protobuf.min.js.map
  10. +31 −0 dist/minimal/README.md
  11. +43 −39 dist/{runtime → minimal}/protobuf.js
  12. +1 −0 dist/minimal/protobuf.js.map
  13. +8 −0 dist/minimal/protobuf.min.js
  14. BIN dist/minimal/protobuf.min.js.gz
  15. +1 −0 dist/minimal/protobuf.min.js.map
  16. +0 −31 dist/noparse/README.md
  17. +0 −1 dist/noparse/protobuf.js.map
  18. +0 −9 dist/noparse/protobuf.min.js
  19. BIN dist/noparse/protobuf.min.js.gz
  20. +0 −1 dist/noparse/protobuf.min.js.map
  21. +21 −19 dist/protobuf.js
  22. +1 −1 dist/protobuf.js.map
  23. +4 −4 dist/protobuf.min.js
  24. BIN dist/protobuf.min.js.gz
  25. +1 −1 dist/protobuf.min.js.map
  26. +0 −31 dist/runtime/README.md
  27. +0 −1 dist/runtime/protobuf.js.map
  28. +0 −8 dist/runtime/protobuf.min.js
  29. BIN dist/runtime/protobuf.min.js.gz
  30. +0 −1 dist/runtime/protobuf.min.js.map
  31. +30 −74 gulpfile.js
  32. +49 −42 index.d.ts
  33. +70 −0 light/index.js
  34. +8 −4 {runtime → minimal}/index.js
  35. +2 −2 package.json
  36. +2 −0 runtime.js
  37. +2 −2 scripts/gentests.js
  38. +13 −6 src/index.js
  39. +1 −1 src/reader.js
  40. +1 −1 src/reader_buffer.js
  41. +5 −10 src/root.js
  42. +1 −1 src/util.js
  43. +1 −1 src/util/longbits.js
  44. 0 src/util/{runtime.js → minimal.js}
  45. +1 −1 src/writer.js
  46. +1 −1 src/writer_buffer.js
  47. +1 −1 tests/data/comments.js
  48. +1 −1 tests/data/convert.js
  49. +1 −1 tests/data/mapbox/vector_tile.js
  50. +1 −1 tests/data/package.js
  51. +1 −1 tests/data/rpc.js
  52. +1 −1 tests/data/test.js
@@ -77,6 +77,14 @@ Or [download](https://github.com/dcodeIO/protobuf.js/tree/master/dist) the libra
The `protobuf` namespace will always be available globally / also supports AMD loaders.
Additionally, the library is compiled in different versions. Which one to use depends on whether size is a factor and your use case:
| Build | Folder | How to require | Description
|---------|------------------------------|---------------------------------|-------------
| full | [dist][dist-full] | `require("protobufjs")` | All features. Works with everything.
| light | [dist/light][dist-light] | `require("protobufjs/light")` | All features except tokenizer, parser and bundled common types. Works with reflection, JSON definitions and static code.
| minimal | [dist/minimal][dist-minimal] | `require("protobufjs/minimal")` | Just enough to run statically generated code. Works with static code only.
Examples
--------
@@ -162,7 +170,7 @@ Custom classes are automatically populated with static `encode`, `encodeDelimite
### Using the Reader/Writer interface directly
While only useful for the adventurous cherishing an aversion to [generated static code](https://github.com/dcodeIO/protobuf.js#command-line), it's also possible to use the Reader/Writer interface directly depending just on the [minimal runtime](https://github.com/dcodeIO/protobuf.js/tree/master/dist/runtime) ([basic example](https://github.com/dcodeIO/protobuf.js/blob/master/examples/reader-writer.js)).
While only useful for the adventurous cherishing an aversion to [generated static code](https://github.com/dcodeIO/protobuf.js#command-line), it's also possible to use the Reader/Writer interface directly depending just on the [minimal library][dist-minimal] ([basic example](https://github.com/dcodeIO/protobuf.js/blob/master/examples/reader-writer.js)).
Easy ways to obtain example code snippets are either setting `protobuf.util.codegen.verbose = true` while watching the magic as it happens, or simply inspecting generated static code.
@@ -308,7 +316,7 @@ As you might have noticed, `pbjs` is also capable of generating static code. For
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
```
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`, which then can be used with just the [minimal runtime](https://github.com/dcodeIO/protobuf.js/tree/master/dist/runtime).
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`, which then can be used with just the [minimal library][dist-minimal].
**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.
@@ -354,9 +362,9 @@ $> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
### On reflection vs. static code
While using .proto files requires the [full library](https://github.com/dcodeIO/protobuf.js/tree/master/dist) (about 18.5kb gzipped) or JSON just the [noparse library](https://github.com/dcodeIO/protobuf.js/tree/master/dist/noparse) (about 15.5kb gzipped), pretty much all code but the relatively short descriptors is shared and all features including reflection and the parser are available.
While using .proto files requires the [full library][dist-full] (about 18.5kb gzipped) or JSON at least the [light library][dist-light] (about 15.5kb gzipped), pretty much all code but the relatively short descriptors is shared and all features including reflection and the parser are available.
Static code, on the other hand, requires just the [minimal runtime](https://github.com/dcodeIO/protobuf.js/tree/master/dist/runtime) (about 5.5kb gzipped), but generates additional, albeit editable, source code without any reflection features.
Static code, on the other hand, requires just the [minimal library][dist-minimal] (about 5.5kb gzipped), but generates additional, albeit editable, source code without any reflection features.
There is no significant difference performance-wise as the code generated statically is pretty much the same as generated at runtime and both are largely interchangeable as seen in the previous section.
@@ -467,7 +475,7 @@ $> cd protobuf.js
$> npm install
```
Building the development and production versions with their respective source maps to `dist/`:
Building the respective development and production versions with their respective source maps to `dist/`:
```
$> npm run build
@@ -493,3 +501,7 @@ By default, protobuf.js integrates into your browserify build-process without re
* If you have any special requirements, there is [the bundler](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/bundle.js) as a reference.
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
[dist-full]: https://github.com/dcodeIO/protobuf.js/tree/master/dist
[dist-light]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/light
[dist-minimal]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/minimal
@@ -3,7 +3,7 @@ module.exports = static_module_target;
// - The default wrapper supports AMD, CommonJS and the global scope (as window.root), in this order.
// - You can specify a custom wrapper with the --wrap argument.
// - CommonJS modules depend on the minimal static runtime for reduced package size with browserify.
// - CommonJS modules depend on the minimal build for reduced package size with browserify.
// - AMD and global scope depend on the full library for now.
var path = require("path"),
@@ -19,7 +19,7 @@ function static_module_target(root, options, callback) {
if (err)
return callback(err);
try {
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/runtime" }, options));
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/minimal" }, options));
} catch (e) {
callback(e);
return;
@@ -1,6 +1,4 @@
This folder contains prebuilt browser versions of [protobuf.js](https://github.com/dcodeIO/protobuf.js). When sending pull requests, it is not required to update these.
Alternatively, you can also use [the minimal runtime](./runtime) when working with statically generated code or [the noparse build](./noparse) when working with JSON generated by `pbjs` *only*.
This folder contains prebuilt browser versions of the full library. When sending pull requests, it is not required to update these.
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
@@ -0,0 +1,31 @@
This folder contains prebuilt browser versions of the light library suitable for use with reflection, static code and JSON descriptors / modules. When sending pull requests, it is not required to update these.
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
CDN usage
---------
Development:
```
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.js"></script>
```
Production:
```
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.min.js"></script>
```
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/tags) your project depends upon.
Frontend usage
--------------
Development:
```
<script src="node_modules/protobufjs/dist/light/protobuf.js"></script>
```
Production:
```
<script src="node_modules/protobufjs/dist/light/protobuf.min.js"></script>
```
Oops, something went wrong.

0 comments on commit 4bff9c3

Please sign in to comment.