Skip to content

Commit 3277540

Browse files
committed
tasks: add uber hacky fix for plotly.min.js in require.js envs
- which is basically what plotly/plotly.py#545 implemented - see browserify/webworkify#29 for more info
1 parent b3086fa commit 3277540

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tasks/bundle.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var UglifyJS = require('uglify-js');
77
var constants = require('./util/constants');
88
var common = require('./util/common');
99
var compressAttributes = require('./util/compress_attributes');
10+
var patchMinified = require('./util/patch_minified');
1011
var doesFileExist = common.doesFileExist;
1112

1213
/*
@@ -83,6 +84,7 @@ function _bundle(pathToIndex, pathToBundle, opts) {
8384

8485
if(outputMinified) {
8586
var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code;
87+
minifiedCode = patchMinified(minifiedCode);
8688

8789
fs.writeFile(pathToMinBundle, minifiedCode, function(err) {
8890
if(err) throw err;

tasks/util/patch_minified.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var STR_TO_REPLACE = 'require("+a(r)+");';
2+
var STR_NEW = 'require("+ a(r) +");';
3+
4+
/* Uber hacky in-house fix to
5+
*
6+
* https://github.com/substack/webworkify/issues/29
7+
*
8+
* so that plotly.min.js loads in Jupyter NBs, more info here:
9+
*
10+
* https://github.com/plotly/plotly.py/pull/545
11+
*
12+
*/
13+
module.exports = function patchMinified(minifiedCode) {
14+
return minifiedCode.replace(STR_TO_REPLACE, STR_NEW);
15+
};

0 commit comments

Comments
 (0)