Skip to content

Commit

Permalink
Other: Bundler provides useful stuff to uglify and a global var witho…
Browse files Browse the repository at this point in the history
…ut extra bloat
  • Loading branch information
dcodeIO committed Jan 17, 2017
1 parent 32e0529 commit 168e448
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"Float32Array": true,
"Float64Array": true,
"define": true,
"global": true,
"XMLHttpRequest": true,
"Promise": true,
"dcodeIO": true
"Promise": true
},
"parserOptions": {
"ecmaVersion": 5
Expand Down
20 changes: 6 additions & 14 deletions dist/noparse/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/noparse/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/noparse/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/noparse/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/noparse/protobuf.min.js.map

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/runtime/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@types/node": "7.0.0",
"benchmark": "^2.1.3",
"browserify": "^13.3.0",
"browserify-wrap": "^1.0.2",
"bundle-collapser": "^1.2.1",
"chalk": "^1.1.3",
"escodegen": "^1.8.1",
Expand Down
9 changes: 1 addition & 8 deletions runtime/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file exports just the bare minimum required to work with statically generated code.
// Can be used as a drop-in replacement for the full library as it has the same general structure.
"use strict";
var protobuf = exports;
var protobuf = global.protobuf = exports;

protobuf.Writer = require("../src/writer");
protobuf.BufferWriter = require("../src/writer_buffer");
Expand All @@ -15,13 +15,6 @@ function configure() {
protobuf.Reader._configure();
}

if (typeof window !== "undefined" && window)
window.protobuf = protobuf;
else if (typeof self !== "undefined" && self)
self.protobuf = protobuf;
else
this.protobuf = protobuf; // eslint-disable-line no-invalid-this

if (typeof define === "function" && define.amd)
define(["long"], function(Long) {
if (Long) {
Expand Down
10 changes: 10 additions & 0 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ function bundle(options) {
if (options.exclude)
options.exclude.forEach(bundler.exclude, bundler);
return bundler
.plugin(require("browserify-wrap"), {
// + global object for convenience
// + undefined var and global strict-mode for uglify
prefix: "!function(global,undefined){\"use strict\";",
suffix: "}(typeof window===\"object\"&&window||typeof self===\"object\"&&self||this);"
})
.plugin(require("bundle-collapser/plugin"))
.bundle()
.pipe(source(options.compress ? "protobuf.min.js" : "protobuf.js"))
Expand All @@ -53,6 +59,10 @@ function bundle(options) {
mangleProperties: {
regex: /^_/
},
mangle: {
eval: true,
toplevel: false
},
compress: {
unused: true,
keep_fargs: false,
Expand Down
10 changes: 1 addition & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
var protobuf = exports;
var protobuf = global.protobuf = exports;

/**
* A node-style callback as used by {@link load} and {@link Root#load}.
Expand Down Expand Up @@ -127,14 +127,6 @@ function configure() {
protobuf.Reader._configure();
}

/* istanbul ignore next */
if (typeof window !== "undefined" && window)
window.protobuf = protobuf;
else if (typeof self !== "undefined" && self)
self.protobuf = protobuf;
else
this.protobuf = protobuf; // eslint-disable-line no-invalid-this

/* istanbul ignore next */
if (typeof define === "function" && define.amd)
define(["long"], function(Long) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next *
* @memberof util
* @type {boolean}
*/
util.isNode = typeof process !== "undefined" && Boolean(process.versions && process.versions.node);
util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);

/**
* Tests if the specified value is an integer.
Expand Down Expand Up @@ -112,7 +112,7 @@ util.LongBits = require("./longbits");
* Long.js's Long class if available.
* @type {?function(new: Long)}
*/
util.Long = typeof dcodeIO !== "undefined" && /* istanbul ignore next */ dcodeIO && /* istanbul ignore next */ dcodeIO.Long || util.inquire("long");
util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");

/**
* Converts a number or long to an 8 characters long hash string.
Expand Down

0 comments on commit 168e448

Please sign in to comment.