ContextDependencyTemplateAsId.js 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class ContextDependencyTemplateAsId {
  7. apply(dep, source, outputOptions, requestShortener) {
  8. const comment = outputOptions.pathinfo ?
  9. "/*! " + requestShortener.shorten(dep.request) + " */ " : "";
  10. if(dep.module && dep.module.dependencies && dep.module.dependencies.length > 0) {
  11. if(dep.valueRange) {
  12. if(Array.isArray(dep.replaces)) {
  13. for(let i = 0; i < dep.replaces.length; i++) {
  14. const rep = dep.replaces[i];
  15. source.replace(rep.range[0], rep.range[1] - 1, rep.value);
  16. }
  17. }
  18. source.replace(dep.valueRange[1], dep.range[1] - 1, ")");
  19. source.replace(dep.range[0], dep.valueRange[0] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve(" + (typeof dep.prepend === "string" ? JSON.stringify(dep.prepend) : "") + "");
  20. } else {
  21. source.replace(dep.range[0], dep.range[1] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve");
  22. }
  23. } else {
  24. const content = require("./WebpackMissingModule").module(dep.request);
  25. source.replace(dep.range[0], dep.range[1] - 1, content);
  26. }
  27. }
  28. }
  29. module.exports = ContextDependencyTemplateAsId;