1 | var makeStealNode = require("../node/make_steal_node"),
|
2 | makeNode = require("../node/make_node"),
|
3 | prettier = require("prettier");
|
4 |
|
5 |
|
6 | module.exports = function(options) {
|
7 | var main = options.main;
|
8 | var bundle = options.bundle;
|
9 | var configuration = options.configuration;
|
10 |
|
11 | bundle.nodes.unshift(
|
12 | makeProductionConfigNode(main, configuration),
|
13 | options.bundlePromisePolyfill ?
|
14 | makeStealNode.withPromises() :
|
15 | makeStealNode.withoutPromises(),
|
16 | makeDefineNode()
|
17 | );
|
18 |
|
19 | bundle.nodes.push(
|
20 | makeNode(
|
21 | "[import-main-module]",
|
22 | prettier.format(
|
23 | `System["import"]("${configuration.configMain}")
|
24 | .then(function() {
|
25 | System["import"]("${main}")
|
26 | });`,
|
27 | { useTabs: true }
|
28 | )
|
29 | )
|
30 | );
|
31 | };
|
32 |
|
33 | function makeProductionConfigNode(main, configuration){
|
34 | var configString = "steal = " + browserGlobal + ".steal || {};\n" +
|
35 | "steal.stealBundled = true;\n" +
|
36 | "steal.loadBundles = true;\n" +
|
37 | "steal.baseURL = './';\n" +
|
38 | "steal.configMain = \"" + configuration.configMain + "\";\n" +
|
39 | "steal.main = \"" + main + "\";";
|
40 | return makeNode("[production-config]", configString);
|
41 | }
|
42 |
|
43 | function makeDefineNode(){
|
44 | return makeNode("[add-define]", browserGlobal + ".define = System.amdDefine;");
|
45 | }
|
46 |
|
47 | var browserGlobal = "((typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) ? self : window)";
|