|
1 | | -var fs = require('fs'); |
| 1 | +var makeWatchifiedBundle = require('./util/make_watchified_bundle'); |
2 | 2 |
|
3 | | -var browserify = require('browserify'); |
4 | | -var watchify = require('watchify'); |
5 | | - |
6 | | -var compressAttributes = require('./util/compress_attributes'); |
7 | | -var formatBundleMsg = require('./util/format_bundle_msg'); |
8 | | -var constants = require('./util/constants'); |
9 | | - |
10 | | -/** |
11 | | - * Make a browserify bundle function watched by watchify. |
12 | | - * |
13 | | - * @param {function} onFirstBundleCallback executed when first bundle is completed |
14 | | - * |
15 | | - */ |
16 | | -function makeWatchifiedBundle(onFirstBundleCallback) { |
17 | | - var b = browserify(constants.pathToPlotlySrc, { |
18 | | - debug: true, |
19 | | - standalone: 'Plotly', |
20 | | - transform: [compressAttributes], |
21 | | - cache: {}, |
22 | | - packageCache: {}, |
23 | | - plugin: [watchify] |
24 | | - }); |
25 | | - |
26 | | - var firstBundle = true; |
27 | | - |
28 | | - if(firstBundle) { |
29 | | - console.log([ |
30 | | - '***', |
31 | | - 'Building the first bundle, this should take ~10 seconds', |
32 | | - '***\n' |
33 | | - ].join(' ')); |
34 | | - } |
35 | | - |
36 | | - b.on('update', bundle); |
37 | | - formatBundleMsg(b, 'plotly.js'); |
38 | | - |
39 | | - function bundle() { |
40 | | - b.bundle(function(err) { |
41 | | - if(err) console.error(JSON.stringify(String(err))); |
42 | | - |
43 | | - if(firstBundle) { |
44 | | - onFirstBundleCallback(); |
45 | | - firstBundle = false; |
46 | | - } |
47 | | - }) |
48 | | - .pipe( |
49 | | - fs.createWriteStream(constants.pathToPlotlyDist) |
50 | | - ); |
51 | | - } |
52 | | - |
53 | | - return bundle; |
54 | | -} |
55 | | - |
56 | | -// call watchifiedBundle if ran in CLI |
57 | | -if(process.argv[1] === __filename) { |
58 | | - var watchifiedBundle = makeWatchifiedBundle(function() {}); |
59 | | - watchifiedBundle(); |
60 | | -} |
61 | | - |
62 | | -// export if required in |
63 | | -module.exports = makeWatchifiedBundle; |
| 3 | +// make watchified bundle and run it! |
| 4 | +var watchifiedBundle = makeWatchifiedBundle(function() {}); |
| 5 | +watchifiedBundle(); |
0 commit comments