Skip to content

Enable compress attributes browserify transform by default #1584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ then simply run,
browserify index.js > bundle.js
```

to trim meta information (and thus save a few bytes), run:


```
browserify -t path/to/plotly.js/tasks/util/compress_attributes.js index.js > bundle.js
```

## Angular CLI

Currently Angular CLI uses Webpack under the hood to bundle and build your Angular application.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
},
"browserify": {
"transform": [
"glslify"
"glslify",
"./tasks/compress_attributes.js"
]
},
"dependencies": {
Expand Down
5 changes: 2 additions & 3 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ tasks.push(function(cb) {
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, {
standalone: 'Plotly',
debug: DEV,
compressAttrs: true,
pathToMinBundle: constants.pathToPlotlyDistMin
}, cb);
});
Expand All @@ -62,11 +61,12 @@ tasks.push(function(cb) {
}, cb);
});

// Browserify the plotly.js with meta
// Browserify plotly.js with meta and output plot-schema JSON
tasks.push(function(cb) {
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, {
standalone: 'Plotly',
debug: DEV,
noCompress: true
}, function() {
makeSchema(constants.pathToPlotlyDistWithMeta, constants.pathToSchema)();
cb();
Expand All @@ -79,7 +79,6 @@ constants.partialBundlePaths.forEach(function(pathObj) {
_bundle(pathObj.index, pathObj.dist, {
standalone: 'Plotly',
debug: DEV,
compressAttrs: true,
pathToMinBundle: pathObj.distMin
}, cb);
});
Expand Down
2 changes: 0 additions & 2 deletions tasks/cibundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ var _bundle = require('./util/browserify_wrapper');
* - plotly.min.js bundle in dist/ (for requirejs test)
*/


// Browserify plotly.js and plotly.min.js
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
standalone: 'Plotly',
debug: true,
compressAttrs: true,
pathToMinBundle: constants.pathToPlotlyDistMin
});

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tasks/util/browserify_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var derequire = require('derequire');
var through = require('through2');

var constants = require('./constants');
var compressAttributes = require('./compress_attributes');
var strictD3 = require('./strict_d3');

/** Convenience browserify wrapper
Expand All @@ -20,7 +19,7 @@ var strictD3 = require('./strict_d3');
* - debug {boolean} [optional]
* Additional option:
* - pathToMinBundle {string} path to destination minified bundle
* - compressAttrs {boolean} do we compress attribute meta?
* - noCompress {boolean} skip attribute meta compression?
* @param {function} cb callback
*
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted
Expand All @@ -38,10 +37,11 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
browserifyOpts.standalone = opts.standalone;
browserifyOpts.debug = opts.debug;

browserifyOpts.transform = [];
if(opts.compressAttrs) {
browserifyOpts.transform.push(compressAttributes);
if(opts.noCompress) {
browserifyOpts.ignoreTransform = './tasks/compress_attributes.js';
}

browserifyOpts.transform = [];
if(opts.debug) {
browserifyOpts.transform.push(strictD3);
}
Expand Down
3 changes: 1 addition & 2 deletions tasks/util/watchified_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var prettySize = require('prettysize');

var constants = require('./constants');
var common = require('./common');
var compressAttributes = require('./compress_attributes');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that this just disappears. Opt-opt also scopes the transform better so it doesn't need to be applied globally 👍

var strictD3 = require('./strict_d3');

/**
Expand All @@ -23,7 +22,7 @@ module.exports = function makeWatchifiedBundle(onFirstBundleCallback) {
var b = browserify(constants.pathToPlotlyIndex, {
debug: true,
standalone: 'Plotly',
transform: [strictD3, compressAttributes],
transform: [strictD3],
cache: {},
packageCache: {},
plugin: [watchify]
Expand Down
4 changes: 4 additions & 0 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ if(isBundleTest) {
func.defaultConfig.files.push(pathToIE9mock);
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
break;
case 'plotschema':
func.defaultConfig.browserify.ignoreTransform = './tasks/compress_attributes.js';
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
break;
default:
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
break;
Expand Down