Skip to content

Commit

Permalink
Breaking: Cleaned up library distributions, now is full / light / min…
Browse files Browse the repository at this point in the history
…imal with proper browserify support for each
  • Loading branch information
dcodeIO committed Jan 20, 2017
1 parent 28ddf75 commit 4bff9c3
Show file tree
Hide file tree
Showing 52 changed files with 572 additions and 588 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions cli/targets/static-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
31 changes: 31 additions & 0 deletions dist/light/README.md
Original file line number Diff line number Diff line change
@@ -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>
```
Loading

0 comments on commit 4bff9c3

Please sign in to comment.