|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var ConcatSource = require("webpack-sources").ConcatSource; |
| 5 | +"use strict"; |
6 | 6 |
|
7 | | -function FunctionModuleTemplatePlugin() {} |
8 | | -module.exports = FunctionModuleTemplatePlugin; |
| 7 | +const ConcatSource = require("webpack-sources").ConcatSource; |
9 | 8 |
|
10 | | -FunctionModuleTemplatePlugin.prototype.apply = function(moduleTemplate) { |
11 | | - moduleTemplate.plugin("render", function(moduleSource, module) { |
12 | | - var source = new ConcatSource(); |
13 | | - var defaultArguments = [module.moduleArgument || "module", module.exportsArgument || "exports"]; |
14 | | - if((module.arguments && module.arguments.length !== 0) || module.hasDependencies(d => d.requireWebpackRequire !== false)) { |
15 | | - defaultArguments.push("__webpack_require__"); |
16 | | - } |
17 | | - source.add("/***/ (function(" + defaultArguments.concat(module.arguments || []).join(", ") + ") {\n\n"); |
18 | | - if(module.strict) source.add("\"use strict\";\n"); |
19 | | - source.add(moduleSource); |
20 | | - source.add("\n\n/***/ })"); |
21 | | - return source; |
22 | | - }); |
23 | | - moduleTemplate.plugin("package", function(moduleSource, module) { |
24 | | - if(this.outputOptions.pathinfo) { |
25 | | - var source = new ConcatSource(); |
26 | | - var req = module.readableIdentifier(this.requestShortener); |
27 | | - if(Array.isArray(module.providedExports)) |
28 | | - source.add("/* exports provided: " + module.providedExports.join(", ") + " */\n"); |
29 | | - else if(module.providedExports) |
30 | | - source.add("/* unknown exports provided */\n"); |
31 | | - if(Array.isArray(module.usedExports)) |
32 | | - source.add("/* exports used: " + module.usedExports.join(", ") + " */\n"); |
33 | | - else if(module.usedExports) |
34 | | - source.add("/* all exports used */\n"); |
35 | | - source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n"); |
36 | | - source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n"); |
37 | | - source.add(" \\****" + req.replace(/./g, "*") + "****/\n"); |
| 9 | +class FunctionModuleTemplatePlugin { |
| 10 | + apply(moduleTemplate) { |
| 11 | + moduleTemplate.plugin("render", function(moduleSource, module) { |
| 12 | + const source = new ConcatSource(); |
| 13 | + const defaultArguments = [module.moduleArgument || "module", module.exportsArgument || "exports"]; |
| 14 | + if((module.arguments && module.arguments.length !== 0) || module.hasDependencies(d => d.requireWebpackRequire !== false)) { |
| 15 | + defaultArguments.push("__webpack_require__"); |
| 16 | + } |
| 17 | + source.add("/***/ (function(" + defaultArguments.concat(module.arguments || []).join(", ") + ") {\n\n"); |
| 18 | + if(module.strict) source.add("\"use strict\";\n"); |
38 | 19 | source.add(moduleSource); |
| 20 | + source.add("\n\n/***/ })"); |
39 | 21 | return source; |
40 | | - } |
41 | | - return moduleSource; |
42 | | - }); |
43 | | - moduleTemplate.plugin("hash", function(hash) { |
44 | | - hash.update("FunctionModuleTemplatePlugin"); |
45 | | - hash.update("2"); |
46 | | - }); |
47 | | -}; |
| 22 | + }); |
| 23 | + |
| 24 | + moduleTemplate.plugin("package", function(moduleSource, module) { |
| 25 | + if(this.outputOptions.pathinfo) { |
| 26 | + const source = new ConcatSource(); |
| 27 | + const req = module.readableIdentifier(this.requestShortener); |
| 28 | + if(Array.isArray(module.providedExports)) |
| 29 | + source.add("/* exports provided: " + module.providedExports.join(", ") + " */\n"); |
| 30 | + else if(module.providedExports) |
| 31 | + source.add("/* unknown exports provided */\n"); |
| 32 | + if(Array.isArray(module.usedExports)) |
| 33 | + source.add("/* exports used: " + module.usedExports.join(", ") + " */\n"); |
| 34 | + else if(module.usedExports) |
| 35 | + source.add("/* all exports used */\n"); |
| 36 | + source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n"); |
| 37 | + source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n"); |
| 38 | + source.add(" \\****" + req.replace(/./g, "*") + "****/\n"); |
| 39 | + source.add(moduleSource); |
| 40 | + return source; |
| 41 | + } |
| 42 | + return moduleSource; |
| 43 | + }); |
| 44 | + |
| 45 | + moduleTemplate.plugin("hash", function(hash) { |
| 46 | + hash.update("FunctionModuleTemplatePlugin"); |
| 47 | + hash.update("2"); |
| 48 | + }); |
| 49 | + } |
| 50 | +} |
| 51 | +module.exports = FunctionModuleTemplatePlugin; |
0 commit comments