UNPKG

1.02 kBJavaScriptView Raw
1var through = require("through2");
2var omit = require("lodash/omit");
3var clone = require("lodash/clone");
4var assign = require("lodash/assign");
5
6module.exports = function(options) {
7 return through.obj(function(data, enc, next) {
8 try {
9 next(null, options.target ? adjustBundlesPath(data, options) : data);
10 } catch (err) {
11 next(err);
12 }
13 });
14};
15
16/**
17 * Appends the target name to the bundles path
18 *
19 * Each target build should be written in its own subfolder, e.g:
20 *
21 * dist/bundles/node
22 * dist/bundles/web
23 * dist/bundles/worker
24 *
25 * This should only happen when target is explicitly set.
26 */
27function adjustBundlesPath(data, options) {
28 var path = require("path");
29 var configuration = clone(data.configuration);
30
31 var bundlesPath = configuration.bundlesPath;
32 Object.defineProperty(configuration, "bundlesPath", {
33 configurable: true,
34 get: function() {
35 return path.join(bundlesPath, options.target);
36 }
37 });
38
39 return assign({}, omit(data, ["configuration"]), {
40 configuration: configuration
41 });
42}