- Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathpartial_bundle.mjs
82 lines (65 loc) · 2.69 KB
/
partial_bundle.mjs
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
importprependFilefrom'prepend-file';
importconstantsfrom'./util/constants.js';
importcommonfrom'./util/common.js';
import_bundlefrom'./util/bundle_wrapper.mjs';
varheader=constants.licenseDist+'\n';
varallTraces=constants.allTraces;
varmainIndex=constants.mainIndex;
varstrictIndex=constants.strictIndex;
// Bundle the plotly.js partial bundles
exportdefaultfunctionpartialBundle(tasks,opts){
varname=opts.name;
varindex=opts.index;
vardeleteIndex=opts.deleteIndex;
vardist=opts.dist;
vardistMin=opts.distMin;
vartraceList=opts.traceList;
varcalendars=opts.calendars;
varstrict=opts.strict;
// skip strict bundle which is no longer a partial bundle and has a special index file for regl traces
if(name!=='strict'){
tasks.push(function(done){
varpartialIndex=(strict) ? strictIndex : mainIndex;
varall=['calendars'].concat(allTraces);
varincludes=(calendars ? ['calendars'] : []).concat(traceList);
varexcludes=all.filter(function(e){returnincludes.indexOf(e)===-1;});
excludes.forEach(function(t){
varWHITESPACE_BEFORE='\\s*';
// remove require
varregEx=WHITESPACE_BEFORE+'require\\(\'\\./'+t+'\'\\),';
if(strict){
regEx+='|require\\(\'\\.\\./src/traces/'+t+'/strict\'\\),';
}
varnewCode=partialIndex.replace(newRegExp(regEx,'g'),'');
// test removal
if(newCode===partialIndex){
console.error('Unable to find and drop require for '+t);
throw'Error generating index for partial bundle!';
}
partialIndex=newCode;
});
common.writeFile(index,partialIndex,done);
});
}
tasks.push(function(done){
varbundleOpts={
deleteIndex: deleteIndex&&!distMin,
};
_bundle(index,dist,bundleOpts,function(){
varheaderDist=header.replace('plotly.js','plotly.js ('+name+')');
if(dist)prependFile.sync(dist,headerDist,common.throwOnError);
done();
});
});
tasks.push(function(done){
varbundleOpts={
deleteIndex: deleteIndex,
minify: true,
};
_bundle(index,distMin,bundleOpts,function(){
varheaderDistMin=header.replace('plotly.js','plotly.js ('+name+' - minified)');
if(distMin)prependFile.sync(distMin,headerDistMin,common.throwOnError);
done();
});
});
}