-
Notifications
You must be signed in to change notification settings - Fork 23
/
transpile.js
54 lines (45 loc) · 1.58 KB
/
transpile.js
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
var clean = require("../graph/clean");
var makeConfiguration = require("../configuration/make");
var pluck = require("../graph/pluck");
var through = require("through2");
var transpile = require("../graph/transpile");
var winston = require("winston");
module.exports = function(options) {
return through.obj(function(data, enc, done){
try {
var buildResult = transpileGraph(data, options || {});
done(null, buildResult);
} catch(err){
done(err);
}
});
};
function transpileGraph(data, transpileOptions) {
var dependencyGraph = data.graph,
options = data.options,
configuration = makeConfiguration(data.loader, data.buildLoader, options);
// Remove @config so it is not transpiled. It is a global,
// but we will want it to run ASAP.
var configGraph = pluck(
dependencyGraph,
data.loader.configMain || "@config",
transpileOptions.keepInGraph || []
);
// Remove steal dev from production builds.
pluck(dependencyGraph, "@dev", transpileOptions.keepInGraph || []);
// Clean development code if the option was passed
if(options.removeDevelopmentCode) {
clean(configGraph, options);
clean(dependencyGraph, options);
}
// Transpile each module to amd. Eventually, production builds
// should be able to work without steal.js.
options.sourceMapPath = configuration.bundlesPath;
winston.info("Transpiling...");
var outputFormat = transpileOptions.outputFormat || "amd";
transpile(dependencyGraph, outputFormat, options, data);
transpile(configGraph, outputFormat, options, data);
data.configGraph = configGraph;
data.configuration = configuration;
return data;
}