|
1 | 1 | var fs = require('fs');
|
| 2 | +var path = require('path'); |
2 | 3 |
|
3 | 4 | var browserify = require('browserify');
|
4 | 5 | var UglifyJS = require('uglify-js');
|
@@ -35,41 +36,55 @@ catch(e) {
|
35 | 36 |
|
36 | 37 |
|
37 | 38 | // Browserify plotly.js
|
38 |
| -browserify(constants.pathToPlotlyIndex, { |
39 |
| - debug: DEV, |
| 39 | +_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, { |
40 | 40 | standalone: 'Plotly',
|
41 |
| - transform: [compressAttributes] |
42 |
| -}) |
43 |
| -.bundle(function(err, buf) { |
44 |
| - if(err) throw err; |
45 |
| - |
46 |
| - // generate plotly.min.js |
47 |
| - if(!DEV) { |
48 |
| - fs.writeFile( |
49 |
| - constants.pathToPlotlyDistMin, |
50 |
| - UglifyJS.minify(buf.toString(), constants.uglifyOptions).code |
51 |
| - ); |
52 |
| - } |
53 |
| -}) |
54 |
| -.pipe(fs.createWriteStream(constants.pathToPlotlyDist)); |
55 |
| - |
| 41 | + debug: DEV, |
| 42 | + pathToMinBundle: constants.pathToPlotlyDistMin |
| 43 | +}); |
56 | 44 |
|
57 | 45 | // Browserify the geo assets
|
58 |
| -browserify(constants.pathToPlotlyGeoAssetsSrc, { |
| 46 | +_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, { |
59 | 47 | standalone: 'PlotlyGeoAssets'
|
60 |
| -}) |
61 |
| -.bundle(function(err) { |
62 |
| - if(err) throw err; |
63 |
| -}) |
64 |
| -.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist)); |
65 |
| - |
| 48 | +}); |
66 | 49 |
|
67 | 50 | // Browserify the plotly.js with meta
|
68 |
| -browserify(constants.pathToPlotlyIndex, { |
69 |
| - debug: DEV, |
70 |
| - standalone: 'Plotly' |
71 |
| -}) |
72 |
| -.bundle(function(err) { |
73 |
| - if(err) throw err; |
74 |
| -}) |
75 |
| -.pipe(fs.createWriteStream(constants.pathToPlotlyDistWithMeta)); |
| 51 | +_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, { |
| 52 | + standalone: 'Plotly', |
| 53 | + debug: DEV |
| 54 | +}); |
| 55 | + |
| 56 | +// Browserify the plotly.js partial bundles |
| 57 | +constants.partialBundleNames.forEach(function(name) { |
| 58 | + var pathToIndex = path.join(constants.pathToLib, 'index-' + name + '.js'), |
| 59 | + pathToBundle = path.join(constants.pathToDist, 'plotly-' + name + '.js'), |
| 60 | + pathToMinBundle = path.join(constants.pathToDist, 'plotly-' + name + '.min.js'); |
| 61 | + |
| 62 | + _bundle(pathToIndex, pathToBundle, { |
| 63 | + standalone: 'Plotly', |
| 64 | + debug: DEV, |
| 65 | + pathToMinBundle: pathToMinBundle |
| 66 | + }); |
| 67 | +}); |
| 68 | + |
| 69 | +function _bundle(pathToIndex, pathToBundle, opts) { |
| 70 | + opts = opts || {}; |
| 71 | + |
| 72 | + // do we output a minified file? |
| 73 | + var outputMinified = !!opts.pathToMinBundle && !opts.debug; |
| 74 | + |
| 75 | + var browserifyOpts = {}; |
| 76 | + browserifyOpts.standalone = opts.standalone; |
| 77 | + browserifyOpts.debug = opts.debug; |
| 78 | + browserifyOpts.transform = outputMinified ? [compressAttributes] : []; |
| 79 | + |
| 80 | + browserify(pathToIndex, browserifyOpts).bundle(function(err, buf) { |
| 81 | + if(err) throw err; |
| 82 | + |
| 83 | + if(outputMinified) { |
| 84 | + var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code; |
| 85 | + |
| 86 | + fs.writeFile(opts.pathToMinBundle, minifiedCode); |
| 87 | + } |
| 88 | + }) |
| 89 | + .pipe(fs.createWriteStream(pathToBundle)); |
| 90 | +} |
0 commit comments