Skip to content

Commit 5e88220

Browse files
7235200TheLarkInn
authored andcommitted
refactor(JsonpExportMainTemplatePlugin): upgrade to ES6 (webpack#3793)
1 parent 83efa1a commit 5e88220

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

lib/JsonpExportMainTemplatePlugin.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,36 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var ConcatSource = require("webpack-sources").ConcatSource;
5+
"use strict";
66

7-
function JsonpExportMainTemplatePlugin(name) {
8-
this.name = name;
7+
const ConcatSource = require("webpack-sources").ConcatSource;
8+
9+
class JsonpExportMainTemplatePlugin {
10+
constructor(name) {
11+
this.name = name;
12+
}
13+
14+
apply(compilation) {
15+
const mainTemplate = compilation.mainTemplate;
16+
17+
compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => {
18+
const name = mainTemplate.applyPluginsWaterfall("asset-path", this.name || "", {
19+
hash: hash,
20+
chunk: chunk
21+
});
22+
return new ConcatSource(`${name}(`, source, ");");
23+
});
24+
25+
mainTemplate.plugin("global-hash-paths", paths => {
26+
if(this.name) paths.push(this.name);
27+
return paths;
28+
});
29+
30+
mainTemplate.plugin("hash", hash => {
31+
hash.update("jsonp export");
32+
hash.update(`${this.name}`);
33+
});
34+
}
935
}
36+
1037
module.exports = JsonpExportMainTemplatePlugin;
11-
JsonpExportMainTemplatePlugin.prototype.apply = function(compilation) {
12-
var mainTemplate = compilation.mainTemplate;
13-
compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
14-
var name = mainTemplate.applyPluginsWaterfall("asset-path", this.name || "", {
15-
hash: hash,
16-
chunk: chunk
17-
});
18-
return new ConcatSource(name + "(", source, ");");
19-
}.bind(this));
20-
mainTemplate.plugin("global-hash-paths", function(paths) {
21-
if(this.name) paths.push(this.name);
22-
return paths;
23-
}.bind(this));
24-
mainTemplate.plugin("hash", function(hash) {
25-
hash.update("jsonp export");
26-
hash.update(this.name + "");
27-
}.bind(this));
28-
};

0 commit comments

Comments
 (0)