forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonpChunkTemplate.js
More file actions
31 lines (28 loc) · 1.04 KB
/
Copy pathJsonpChunkTemplate.js
File metadata and controls
31 lines (28 loc) · 1.04 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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var RawSource = require("webpack-core/lib/RawSource");
function JsonpChunkTemplate(outputOptions) {
this.outputOptions = outputOptions || {};
}
module.exports = JsonpChunkTemplate;
JsonpChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
var jsonpFunction = this.outputOptions.jsonpFunction || ("webpackJsonp" + (this.outputOptions.library || ""));
var buf = [];
buf.push(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ", {\n");
chunk.modules.forEach(function(module, idx) {
if(idx != 0) buf.push(",\n");
buf.push("\n/***/ " + module.id + ":\n");
var source = moduleTemplate.render(module, dependencyTemplates);
buf.push(source.source());
});
buf.push("\n\n})");
return new RawSource(buf.join(""));
};
JsonpChunkTemplate.prototype.updateHash = function(hash) {
hash.update("jsonp");
hash.update("2");
hash.update(this.outputOptions.jsonpFunction + "");
hash.update(this.outputOptions.library + "");
};