/
bundle.js
57 lines (49 loc) · 1.56 KB
/
bundle.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
55
56
57
var pump = require("pump");
var assign = require("lodash/assign");
var minify = require("../stream/minify");
var transpile = require("../stream/transpile");
var concat = require("../bundle/concat_stream");
var makeBundle = require("../stream/make_bundle");
var filterBundleGraph = require("../stream/filter_bundle_graph");
var assignDefaultOptions = require("../assign_default_options");
var createWriteStream = require("../bundle/write_bundles").createWriteStream;
var createBundleGraphStream = require("../graph/make_graph_with_bundles").createBundleGraphStream;
module.exports = function(config, options) {
// Use the build-development environment.
if (!options) options = {};
var isDestProvided = !!options.dest;
// minification is on by default
options.minify = options.minify == null ? true : options.minify;
try {
options = assignDefaultOptions(config, options);
} catch(err) {
return Promise.reject(err);
}
// if `dest` was not provided in the options object, override the default
// value so the development bundle is written out in the root folder
assign(options, {
defaultBundlesPathName: "",
dest: isDestProvided ? options.dest : "",
buildStealConfig: {
env: "bundle-build"
}
});
return new Promise(function(resolve, reject) {
var writeStream = pump(
createBundleGraphStream(config, options),
filterBundleGraph(),
transpile(),
minify(),
makeBundle(),
concat(),
createWriteStream(),
function(err) {
if (err) reject(err);
}
);
writeStream.on("data", function(data){
this.end();
resolve(data);
});
});
};