Skip to content

Commit 7b05183

Browse files
committed
use 'browser-pack-flat' to reduce minified bundle size!
- https://github.com/goto-bus-stop/browser-pack-flat
1 parent b861883 commit 7b05183

File tree

4 files changed

+138
-3
lines changed

4 files changed

+138
-3
lines changed

package-lock.json

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
},
115115
"devDependencies": {
116116
"brfs": "^1.4.4",
117+
"browser-pack-flat": "^3.0.8",
117118
"browserify": "^15.2.0",
118119
"browserify-transform-tools": "^1.7.0",
119120
"check-node-version": "^3.2.0",

tasks/bundle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tasks.push(function(cb) {
5151
standalone: 'Plotly',
5252
debug: DEV,
5353
compressAttrs: true,
54+
packFlat: true,
5455
pathToMinBundle: constants.pathToPlotlyDistMin
5556
}, cb);
5657
});
@@ -67,6 +68,7 @@ tasks.push(function(cb) {
6768
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, {
6869
standalone: 'Plotly',
6970
debug: DEV,
71+
packFlat: true
7072
}, function() {
7173
makeSchema(constants.pathToPlotlyDistWithMeta, constants.pathToSchema)();
7274
cb();
@@ -80,6 +82,7 @@ constants.partialBundlePaths.forEach(function(pathObj) {
8082
standalone: 'Plotly',
8183
debug: DEV,
8284
compressAttrs: true,
85+
packFlat: true,
8386
pathToMinBundle: pathObj.distMin
8487
}, cb);
8588
});

tasks/util/browserify_wrapper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var fs = require('fs');
22
var path = require('path');
33

44
var browserify = require('browserify');
5+
var packFlat = require('browser-pack-flat/plugin');
56
var minify = require('minify-stream');
67

78
var constants = require('./constants');
@@ -12,16 +13,14 @@ var strictD3 = require('./strict_d3');
1213
*
1314
* @param {string} pathToIndex path to index file to bundle
1415
* @param {string} pathToBunlde path to destination bundle
15-
*
1616
* @param {object} opts
17-
*
1817
* Browserify options:
1918
* - standalone {string}
2019
* - debug {boolean} [optional]
21-
*
2220
* Additional option:
2321
* - pathToMinBundle {string} path to destination minified bundle
2422
* - compressAttrs {boolean} do we compress attribute meta?
23+
* - packFlat {boolean} do we use browser-pack-flat plugin?
2524
* @param {function} cb callback
2625
*
2726
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted
@@ -49,6 +48,9 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
4948

5049
var b = browserify(pathToIndex, browserifyOpts);
5150

51+
if(opts.packFlat) {
52+
b.plugin(packFlat);
53+
}
5254

5355
var pending = opts.pathToMinBundle ? 2 : 1;
5456

0 commit comments

Comments
 (0)