1 |
|
2 | var makeNode = require("../node/make_node"),
|
3 | minify = require("../graph/minify"),
|
4 | fs = require("fs"),
|
5 | path = require("path"),
|
6 | prettier = require("prettier");
|
7 |
|
8 |
|
9 | module.exports = function(bundle, options){
|
10 | var processFn = fs.readFileSync(path.join(__dirname, "shim-process.js"));
|
11 | var env = options.env || "development";
|
12 |
|
13 |
|
14 | var g = `typeof self == "object" && self.Object == Object ? self : (typeof process === "object" && Object.prototype.toString.call(process) === "[object process]") ? global : window`;
|
15 |
|
16 | var source = prettier.format(
|
17 | `(${processFn.toString()})(
|
18 | ${g},
|
19 | ${JSON.stringify(env)}
|
20 | );`,
|
21 | { useTabs: true }
|
22 | );
|
23 |
|
24 | var start = makeNode("[process-shim]", source);
|
25 |
|
26 | if(options.minify){
|
27 | minify([start]);
|
28 | }
|
29 | bundle.nodes.unshift(start);
|
30 | };
|