Skip to content

Commit 344b82b

Browse files
author
Nick Plekhanov
committed
Refactor plugin in ES6
1 parent 3afd802 commit 344b82b

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

‎lib/ExtendedAPIPlugin.js‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
Author Tobias Koppers @sokra
44
*/
55
"use strict";
6-
var ConstDependency = require("./dependencies/ConstDependency");
7-
const ParserHelpers = require("./ParserHelpers");
8-
9-
var NullFactory = require("./NullFactory");
106

11-
function ExtendedAPIPlugin() {}
12-
module.exports = ExtendedAPIPlugin;
7+
const ConstDependency = require("./dependencies/ConstDependency");
8+
const ParserHelpers = require("./ParserHelpers");
9+
const NullFactory = require("./NullFactory");
1310

14-
var REPLACEMENTS = {
11+
const REPLACEMENTS = {
1512
__webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase
1613
};
17-
var REPLACEMENT_TYPES = {
14+
const REPLACEMENT_TYPES = {
1815
__webpack_hash__: "string" // eslint-disable-line camelcase
1916
};
20-
ExtendedAPIPlugin.prototype.apply = function(compiler) {
21-
compiler.plugin("compilation", function(compilation, params) {
22-
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
23-
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
24-
compilation.mainTemplate.plugin("require-extensions", function(source, chunk, hash) {
25-
var buf = [source];
26-
buf.push("");
27-
buf.push("// __webpack_hash__");
28-
buf.push(this.requireFn + ".h = " + JSON.stringify(hash) + ";");
29-
return this.asString(buf);
30-
});
31-
compilation.mainTemplate.plugin("global-hash", function() {
32-
return true;
33-
});
3417

35-
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
36-
Object.keys(REPLACEMENTS).forEach(function(key) {
37-
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(REPLACEMENTS[key]));
38-
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
18+
class ExtendedAPIPlugin {
19+
apply(compiler) {
20+
compiler.plugin("compilation", (compilation, params) => {
21+
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
22+
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
23+
compilation.mainTemplate.plugin("require-extensions", function(source, chunk, hash) {
24+
var buf = [source];
25+
buf.push("");
26+
buf.push("// __webpack_hash__");
27+
buf.push(this.requireFn + ".h = " + JSON.stringify(hash) + ";");
28+
return this.asString(buf);
29+
});
30+
compilation.mainTemplate.plugin("global-hash", () => true);
31+
32+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
33+
Object.keys(REPLACEMENTS).forEach(key => {
34+
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(REPLACEMENTS[key]));
35+
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
36+
});
3937
});
4038
});
41-
});
42-
};
39+
}
40+
}
41+
42+
module.exports = ExtendedAPIPlugin;

0 commit comments

Comments
 (0)