From cf4133d453bae88b77491a15acba4edecd8dc4a5 Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 22 Jan 2021 16:22:32 -0500 Subject: [PATCH] avoid redundant plotly.js Copyright comments in bundles --- package.json | 1 + tasks/compress_headers.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tasks/compress_headers.js diff --git a/package.json b/package.json index 63bbe4b860d..dce2c60936d 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "browserify": { "transform": [ "glslify", + "./tasks/compress_headers.js", "./tasks/compress_attributes.js" ] }, diff --git a/tasks/compress_headers.js b/tasks/compress_headers.js new file mode 100644 index 00000000000..9f06366c202 --- /dev/null +++ b/tasks/compress_headers.js @@ -0,0 +1,27 @@ +var through = require('through2'); + +var licenseSrc = require('./util/constants').licenseSrc + .replace(/\//g, '\\/') + .replace(/\*/g, '\\*') + .replace(/\n/g, '[^]'); + +/** + * Browserify transform that strips redundant plotly.js Copyright comments out + * of the plotly.js bundles + */ + +var WHITESPACE_BEFORE = '\\s*'; + +module.exports = function() { + var allChunks = []; + return through(function(chunk, enc, next) { + allChunks.push(chunk); + next(); + }, function(done) { + var str = Buffer.concat(allChunks).toString('utf-8'); + this.push( + str.replace(new RegExp(WHITESPACE_BEFORE + licenseSrc, 'g'), '') + ); + done(); + }); +};