|
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | 5 | "use strict"; |
6 | | -var ConstDependency = require("./dependencies/ConstDependency"); |
7 | | -const ParserHelpers = require("./ParserHelpers"); |
8 | | - |
9 | | -var NullFactory = require("./NullFactory"); |
10 | 6 |
|
11 | | -function ExtendedAPIPlugin() {} |
12 | | -module.exports = ExtendedAPIPlugin; |
| 7 | +const ConstDependency = require("./dependencies/ConstDependency"); |
| 8 | +const ParserHelpers = require("./ParserHelpers"); |
| 9 | +const NullFactory = require("./NullFactory"); |
13 | 10 |
|
14 | | -var REPLACEMENTS = { |
| 11 | +const REPLACEMENTS = { |
15 | 12 | __webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase |
16 | 13 | }; |
17 | | -var REPLACEMENT_TYPES = { |
| 14 | +const REPLACEMENT_TYPES = { |
18 | 15 | __webpack_hash__: "string" // eslint-disable-line camelcase |
19 | 16 | }; |
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 | | - }); |
34 | 17 |
|
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 | + }); |
39 | 37 | }); |
40 | 38 | }); |
41 | | - }); |
42 | | -}; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +module.exports = ExtendedAPIPlugin; |
0 commit comments