forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteChunk.js
More file actions
50 lines (49 loc) · 1.41 KB
/
writeChunk.js
File metadata and controls
50 lines (49 loc) · 1.41 KB
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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var writeSource = require("./writeSource");
/**
* return the content of a chunk:
* [id]: function(...) {
* [source]
* },
*/
module.exports = function(depTree, chunk, options) {
if(!options) {
options = chunk;
chunk = null;
}
var buffer = [];
var modules = chunk ? chunk.modules : depTree.modules;
var includedModules = [];
for(var moduleId in modules) {
if(chunk) {
if(chunk.modules[moduleId] !== "include")
continue;
}
var module = depTree.modules[moduleId];
includedModules.push(module);
}
if(options.includeFilenames)
var shortenFilename = require("./createFilenameShortener")(options.context);
includedModules.sort(function(a, b) { return a.realId - b.realId; });
includedModules.forEach(function(module, idx) {
buffer.push("/******/");
buffer.push(module.realId);
buffer.push(": function(module, exports, require) {\n\n");
if(options.includeFilenames) {
buffer.push("/**! ");
buffer.push(shortenFilename(module.request || module.dirname));
buffer.push(" !**/\n\n");
}
buffer.push(writeSource(module, options,
function(id) { return depTree.modules[id].realId },
function(id) { return depTree.chunks[id].realId }));
if(idx === includedModules.length - 1)
buffer.push("\n\n/******/}\n");
else
buffer.push("\n\n/******/},\n/******/\n");
});
return buffer.join("");
}