Skip to content

Commit

Permalink
v0.3.0: new support for Service
Browse files Browse the repository at this point in the history
  • Loading branch information
mustime committed Oct 25, 2022
1 parent c1170e4 commit 7543087
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 105 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ English | [中文](https://github.com/mustime/minipbjs/blob/main/README.zh-CN.md

**minipbjs** is a command line tool based on `pbjs` from [protobuf.js](https://github.com/protobufjs/protobuf.js) project, which targets on minimizing the generated javascript code while keeping the same functionality. Compatible to `Node.js`, browsers, wechat miniprogram and other instant-games. Making it perfectly suitable for the scenarios like wechat miniprogram which requires code size restrictions.

`minipbjs` currently supports:

* [x] `message`
* constructor
* create
* encode / encodeDelimited
* decode / decodeDelimited
* verify
* fromObject
* toObject
* toJSON
* [x] `service`
* constructor
* create
* [x] `enum`
* [ ] `oneof` (PRs are appreciated! 🎉)

## Installation & Example

### installing
Expand Down Expand Up @@ -63,11 +80,11 @@ console.log(foo.b, foo2.b, foo3.b);

The Javascript static code generated by `pbjs --target static` contains function stubs like `constructor`, `create`, `encode`, `decode`, `fromObject` and `toObject`, etc. These function stubs are generated individually for **each** message. Which means that these function stubs are distinguish to each other and unlikely be able to share with other messages. Normally we have to strip some less frequently used functionality like `create`/`fromObject`/`toObject` by `--no-create`/`--no-convert`, etc., but the resulting min.js is usually remarkable huge.

However, `minipbjs` pulls basic info from each message(id, name, default value, options, etc.) into a single map. And providing major functionality(currently supports `create`/`encode`/`decode`/`encodeDelimited`/`decodeDelimited`/`fromObject`/`toObject`/`toJSON`/`verify`) as shared implements for all message. No need to care about the negligible code size anymore.
However, `minipbjs` pulls basic info from each message(id, name, default value, options, etc.) into a single map. And providing all major functionalities as shared implements for all messages. No need to care about the negligible code size anymore.

### Comparison

Take my recent project as example, which is a wechat minigame contains more than 2500 messages. On my 2019 RMBP-15, it costs more than 40s to run `pbjs --target static`, resulting in a 5.2+m min.js file. Meanwhile, running with `minipbjs`(remove `--target static` option as well, or minipbjs will perform the same as pbjs) costs only 1.6s, resulting with a 160+kB min.js.
Take my recent project as example, which is a wechat minigame contains more than 2500 messages. On my 2019 RMBP-15, it costs more than 40s to run `pbjs --target static`, come up with a 5.2+m min.js file. Meanwhile, running with `minipbjs`(remove `--target static` option as well, or minipbjs will perform the same as pbjs) costs only 1.6s, come up with a 160+kB min.js.

## Liscense

Expand Down
17 changes: 17 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

**minipbjs**是一个基于[protobuf.js](https://github.com/protobufjs/protobuf.js)下命令行工具`pbjs`的扩展,目的在于大大减少其生成的Javascript胶水代码大小,兼容`Node.js`、浏览器和各类微信小程序(游戏)等。对于小程序(游戏)等对代码包大小有严格要求的场景尤其适用。

`minipbjs` 当前支持:

* [x] `message`
* constructor
* create
* encode / encodeDelimited
* decode / decodeDelimited
* verify
* fromObject
* toObject
* toJSON
* [x] `service`
* constructor
* create
* [x] `enum`
* [ ] `oneof` (欢迎PR!🎉)

## 安装使用

### 安装
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minipbjs",
"version": "0.2.5",
"version": "0.3.0",
"description": "minimizes javascript created by pbjs for code size reduction",
"main": "cli/index.js",
"bin": {
Expand Down
Loading

0 comments on commit 7543087

Please sign in to comment.