Skip to content

Commit 4bff9c3

Browse files
committed
Breaking: Cleaned up library distributions, now is full / light / minimal with proper browserify support for each
1 parent 28ddf75 commit 4bff9c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+572
-588
lines changed

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ Or [download](https://github.com/dcodeIO/protobuf.js/tree/master/dist) the libra
7777

7878
The `protobuf` namespace will always be available globally / also supports AMD loaders.
7979

80+
Additionally, the library is compiled in different versions. Which one to use depends on whether size is a factor and your use case:
81+
82+
| Build | Folder | How to require | Description
83+
|---------|------------------------------|---------------------------------|-------------
84+
| full | [dist][dist-full] | `require("protobufjs")` | All features. Works with everything.
85+
| 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.
86+
| minimal | [dist/minimal][dist-minimal] | `require("protobufjs/minimal")` | Just enough to run statically generated code. Works with static code only.
87+
8088
Examples
8189
--------
8290

@@ -162,7 +170,7 @@ Custom classes are automatically populated with static `encode`, `encodeDelimite
162170

163171
### Using the Reader/Writer interface directly
164172

165-
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)).
173+
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)).
166174

167175
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.
168176

@@ -308,7 +316,7 @@ As you might have noticed, `pbjs` is also capable of generating static code. For
308316
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
309317
```
310318

311-
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).
319+
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].
312320

313321
**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.
314322

@@ -354,9 +362,9 @@ $> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
354362

355363
### On reflection vs. static code
356364

357-
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.
365+
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.
358366

359-
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.
367+
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.
360368

361369
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.
362370

@@ -467,7 +475,7 @@ $> cd protobuf.js
467475
$> npm install
468476
```
469477

470-
Building the development and production versions with their respective source maps to `dist/`:
478+
Building the respective development and production versions with their respective source maps to `dist/`:
471479

472480
```
473481
$> npm run build
@@ -493,3 +501,7 @@ By default, protobuf.js integrates into your browserify build-process without re
493501
* If you have any special requirements, there is [the bundler](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/bundle.js) as a reference.
494502

495503
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
504+
505+
[dist-full]: https://github.com/dcodeIO/protobuf.js/tree/master/dist
506+
[dist-light]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/light
507+
[dist-minimal]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/minimal

cli/targets/static-module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = static_module_target;
33

44
// - The default wrapper supports AMD, CommonJS and the global scope (as window.root), in this order.
55
// - You can specify a custom wrapper with the --wrap argument.
6-
// - CommonJS modules depend on the minimal static runtime for reduced package size with browserify.
6+
// - CommonJS modules depend on the minimal build for reduced package size with browserify.
77
// - AMD and global scope depend on the full library for now.
88

99
var path = require("path"),
@@ -19,7 +19,7 @@ function static_module_target(root, options, callback) {
1919
if (err)
2020
return callback(err);
2121
try {
22-
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/runtime" }, options));
22+
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/minimal" }, options));
2323
} catch (e) {
2424
callback(e);
2525
return;

dist/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
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.
2-
3-
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*.
1+
This folder contains prebuilt browser versions of the full library. When sending pull requests, it is not required to update these.
42

53
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
64

dist/light/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
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.
2+
3+
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
4+
5+
CDN usage
6+
---------
7+
8+
Development:
9+
```
10+
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.js"></script>
11+
```
12+
13+
Production:
14+
```
15+
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.min.js"></script>
16+
```
17+
18+
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/tags) your project depends upon.
19+
20+
Frontend usage
21+
--------------
22+
23+
Development:
24+
```
25+
<script src="node_modules/protobufjs/dist/light/protobuf.js"></script>
26+
```
27+
28+
Production:
29+
```
30+
<script src="node_modules/protobufjs/dist/light/protobuf.min.js"></script>
31+
```

0 commit comments

Comments
 (0)