|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var Module = require("./Module"); |
6 | | -var RawSource = require("webpack-sources").RawSource; |
| 5 | +"use strict"; |
7 | 6 |
|
8 | | -function MultiModule(context, dependencies, name) { |
9 | | - Module.call(this); |
10 | | - this.context = context; |
11 | | - this.dependencies = dependencies; |
12 | | - this.name = name; |
13 | | - this.built = false; |
14 | | - this.cacheable = true; |
15 | | -} |
16 | | -module.exports = MultiModule; |
| 7 | +const Module = require("./Module"); |
| 8 | +const RawSource = require("webpack-sources").RawSource; |
| 9 | + |
| 10 | +class MultiModule extends Module { |
17 | 11 |
|
18 | | -MultiModule.prototype = Object.create(Module.prototype); |
19 | | -MultiModule.prototype.constructor = MultiModule; |
| 12 | + constructor(context, dependencies, name) { |
| 13 | + super(); |
| 14 | + this.context = context; |
| 15 | + this.dependencies = dependencies; |
| 16 | + this.name = name; |
| 17 | + this.built = false; |
| 18 | + this.cacheable = true; |
| 19 | + } |
20 | 20 |
|
21 | | -MultiModule.prototype.identifier = function() { |
22 | | - return "multi " + this.dependencies.map((d) => d.request).join(" "); |
23 | | -}; |
| 21 | + identifier() { |
| 22 | + return `multi ${this.dependencies.map((d) => d.request).join(" ")}`; |
| 23 | + } |
24 | 24 |
|
25 | | -MultiModule.prototype.readableIdentifier = function(requestShortener) { |
26 | | - return "multi " + this.dependencies.map((d) => { |
27 | | - return requestShortener.shorten(d.request); |
28 | | - }).join(" "); |
29 | | -}; |
| 25 | + readableIdentifier(requestShortener) { |
| 26 | + return `multi ${this.dependencies.map((d) => requestShortener.shorten(d.request)).join(" ")}`; |
| 27 | + } |
30 | 28 |
|
31 | | -MultiModule.prototype.disconnect = function disconnect() { |
32 | | - this.built = false; |
33 | | - Module.prototype.disconnect.call(this); |
34 | | -}; |
| 29 | + disconnect() { |
| 30 | + this.built = false; |
| 31 | + super.disconnect(); |
| 32 | + } |
35 | 33 |
|
36 | | -MultiModule.prototype.build = function build(options, compilation, resolver, fs, callback) { |
37 | | - this.built = true; |
38 | | - return callback(); |
39 | | -}; |
| 34 | + build(options, compilation, resolver, fs, callback) { |
| 35 | + this.built = true; |
| 36 | + return callback(); |
| 37 | + } |
40 | 38 |
|
41 | | -MultiModule.prototype.source = function(dependencyTemplates, outputOptions) { |
42 | | - var str = []; |
43 | | - this.dependencies.forEach(function(dep, idx) { |
44 | | - if(dep.module) { |
45 | | - if(idx === this.dependencies.length - 1) |
46 | | - str.push("module.exports = "); |
47 | | - str.push("__webpack_require__("); |
48 | | - if(outputOptions.pathinfo) |
49 | | - str.push("/*! " + dep.request + " */"); |
50 | | - str.push("" + JSON.stringify(dep.module.id)); |
51 | | - str.push(")"); |
52 | | - } else { |
53 | | - str.push("(function webpackMissingModule() { throw new Error("); |
54 | | - str.push(JSON.stringify("Cannot find module \"" + dep.request + "\"")); |
55 | | - str.push("); }())"); |
56 | | - } |
57 | | - str.push(";\n"); |
58 | | - }, this); |
59 | | - return new RawSource(str.join("")); |
60 | | -}; |
| 39 | + needRebuild() { |
| 40 | + return false; |
| 41 | + } |
61 | 42 |
|
62 | | -MultiModule.prototype.needRebuild = function needRebuild() { |
63 | | - return false; |
64 | | -}; |
| 43 | + size() { |
| 44 | + return 16 + this.dependencies.length * 12; |
| 45 | + } |
65 | 46 |
|
66 | | -MultiModule.prototype.size = function() { |
67 | | - return 16 + this.dependencies.length * 12; |
68 | | -}; |
| 47 | + updateHash(hash) { |
| 48 | + hash.update("multi module"); |
| 49 | + hash.update(this.name || ""); |
| 50 | + super.updateHash(hash); |
| 51 | + } |
69 | 52 |
|
70 | | -MultiModule.prototype.updateHash = function(hash) { |
71 | | - hash.update("multi module"); |
72 | | - hash.update(this.name || ""); |
73 | | - Module.prototype.updateHash.call(this, hash); |
74 | | -}; |
| 53 | + source(dependencyTemplates, outputOptions) { |
| 54 | + const str = []; |
| 55 | + this.dependencies.forEach(function(dep, idx) { |
| 56 | + if(dep.module) { |
| 57 | + if(idx === this.dependencies.length - 1) |
| 58 | + str.push("module.exports = "); |
| 59 | + str.push("__webpack_require__("); |
| 60 | + if(outputOptions.pathinfo) |
| 61 | + str.push(`/*! ${dep.request} */`); |
| 62 | + str.push(`${JSON.stringify(dep.module.id)}`); |
| 63 | + str.push(")"); |
| 64 | + } else { |
| 65 | + str.push("(function webpackMissingModule() { throw new Error("); |
| 66 | + str.push(JSON.stringify(`Cannot find module "${dep.request}"`)); |
| 67 | + str.push("); }())"); |
| 68 | + } |
| 69 | + str.push(";\n"); |
| 70 | + }, this); |
| 71 | + return new RawSource(str.join("")); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +module.exports = MultiModule; |
0 commit comments