1 | var path = require("path");
|
2 | var concat = require("../source-map-concat");
|
3 | var sourceNode = require("../node/source").node;
|
4 | var removeSourceMapUrl = require("../remove_source_map_url");
|
5 |
|
6 | module.exports = function(bundle, options){
|
7 | var sourceProp = options.sourceProp;
|
8 | var excludePlugins = options.excludePlugins;
|
9 |
|
10 | var output = fileName(bundle);
|
11 |
|
12 | var makeCode = function(name) {
|
13 | return "define('" + name + "', [], function(){ return {}; });";
|
14 | };
|
15 |
|
16 | var nodes = bundle.nodes.map(function(node){
|
17 | if (node.load.metadata &&
|
18 | node.load.metadata.hasOwnProperty('bundle') &&
|
19 | node.load.metadata.bundle === false) {
|
20 |
|
21 | return { node: node, code: "", map: "" };
|
22 | }
|
23 |
|
24 |
|
25 | if(node.load.excludeFromBuild) {
|
26 | return undefined;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 | if (node.isPlugin &&
|
32 | !node.value.includeInBuild &&
|
33 | !node.load.metadata.includeInBuild) {
|
34 |
|
35 | var code = excludePlugins ? "" : makeCode(node.load.name);
|
36 | return { node: node, code: code };
|
37 | }
|
38 |
|
39 | var source = sourceNode(node, sourceProp);
|
40 |
|
41 | return {
|
42 | node: node,
|
43 | code: removeSourceMapUrl((source.code || "") + ""),
|
44 | map: source.map
|
45 | };
|
46 | }).filter(truthy);
|
47 |
|
48 | var concatenated = concat(nodes, {
|
49 | mapPath: output + ".map",
|
50 | delimiter: "\n",
|
51 | process: prependName
|
52 | });
|
53 |
|
54 | var result = concatenated.toStringWithSourceMap({
|
55 | file: path.basename(output)
|
56 | });
|
57 |
|
58 | bundle.source = result;
|
59 |
|
60 | function prependName(node, file) {
|
61 | var load = file.node.load;
|
62 | var prepend = node.prependModuleName !== false && load.name &&
|
63 | load.metadata.prependModuleName !== false;
|
64 |
|
65 | if(prepend) {
|
66 | node.prepend("/*"+file.node.load.name+"*/\n");
|
67 | }
|
68 | }
|
69 | };
|
70 |
|
71 | function fileName(bundle) {
|
72 | var name = bundle.name || bundle.bundles[0] || bundle.nodes[0].load.name;
|
73 | return name .replace("bundles/", "").replace(/\..+!/, "") + "." + bundle.buildType;
|
74 | }
|
75 |
|
76 | function truthy(x) { return !!x; }
|