forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
90 lines (77 loc) · 2.34 KB
/
bundle.js
File metadata and controls
90 lines (77 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var fs = require('fs');
var browserify = require('browserify');
var UglifyJS = require('uglify-js');
var compressAttributes = require('./util/compress_attributes');
var appendVersion = require('./util/append_version');
var constants = require('./util/constants');
/*
* This script takes one argument
*
* Run `npm run build -- dev` or `npm run build -- --dev`
* to include source map in the plotly.js bundle
*
* N.B. This script is meant for dist builds; the output bundles are placed
* in plotly.js/dist/.
* Use `npm run watch` for dev builds.
*/
var arg = process.argv[2];
var DEV = (arg === 'dev') || (arg === '--dev');
// Check if style and font build files are there
try {
fs.statSync(constants.pathToCSSBuild).isFile();
fs.statSync(constants.pathToFontSVGBuild).isFile();
}
catch(e) {
throw new Error([
'build/ is missing a or more files',
'Please run `npm run preprocess` first'
].join('\n'));
}
// Browserify plotly.js
browserify(constants.pathToPlotlySrc, {
debug: DEV,
standalone: 'Plotly',
transform: [compressAttributes]
})
.bundle(function(err, buf) {
if(err) throw err;
// generate plotly.min.js
if(!DEV) {
fs.writeFile(
constants.pathToPlotlyDistMin,
UglifyJS.minify(buf.toString(), constants.uglifyOptions).code,
function() {
appendVersion(
constants.pathToPlotlyDistMin, {object: 'Plotly'}
);
}
);
}
})
.pipe(fs.createWriteStream(constants.pathToPlotlyDist))
.on('finish', function() {
appendVersion(constants.pathToPlotlyDist, {object: 'Plotly', DEV: DEV});
});
// Browserify the geo assets
browserify(constants.pathToPlotlyGeoAssetsSrc, {
standalone: 'PlotlyGeoAssets'
})
.bundle(function(err) {
if(err) throw err;
})
.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist))
.on('finish', function() {
appendVersion(constants.pathToPlotlyGeoAssetsDist, {object: 'PlotlyGeoAssets'});
});
// Browserify the plotly.js with meta
browserify(constants.pathToPlotlySrc, {
debug: DEV,
standalone: 'Plotly'
})
.bundle(function(err) {
if(err) throw err;
})
.pipe(fs.createWriteStream(constants.pathToPlotlyDistWithMeta))
.on('finish', function() {
appendVersion(constants.pathToPlotlyDistWithMeta, {object: 'Plotly', DEV: DEV});
});