MultiModule.js 1.7KB

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