arcsapp_bundler.js
997 Bytes
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
/** The aim of this part is to provide a bundler for the arcsapp so that less files are downloaded at runtime
*
*/
const path=require('path');
module.exports = function arcsappToJs(options, loaderContext, content) {
// content is here our file arcsapp.json
let descr = JSON.parse(content);
let code = `import ARCS from '../../build/arcs.js';\n`;
let libs = [];
let libCnt = 0;
descr.context.libraries.forEach( e => {
let libPath = path.resolve(__dirname, '../build', e);
code += `import __obj${libCnt} from '${libPath}';\n`;
libs.push(`__obj${libCnt}`);
libCnt ++;
});
code += `let descr=${content};\n`;
code += `let aap = new ARCS.Application();\n`;
code += `aap.import(descr);\n`;
libs.forEach( l => {
code += `aap.getContext().addFactories(${l});\n`;
});
code += `aap.start();\n`;
return {
cacheable : true,
code : code
};
};