RequireIncludeDependency.js 995 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DependencyReference = require("./DependencyReference");
  7. const ModuleDependency = require("./ModuleDependency");
  8. const Template = require("../Template");
  9. class RequireIncludeDependency extends ModuleDependency {
  10. constructor(request, range) {
  11. super(request);
  12. this.range = range;
  13. }
  14. getReference() {
  15. if (!this.module) return null;
  16. // This doesn't use any export
  17. return new DependencyReference(this.module, [], false);
  18. }
  19. get type() {
  20. return "require.include";
  21. }
  22. }
  23. RequireIncludeDependency.Template = class RequireIncludeDependencyTemplate {
  24. apply(dep, source, runtime) {
  25. const comment = runtime.outputOptions.pathinfo
  26. ? Template.toComment(
  27. `require.include ${runtime.requestShortener.shorten(dep.request)}`
  28. )
  29. : "";
  30. source.replace(dep.range[0], dep.range[1] - 1, `undefined${comment}`);
  31. }
  32. };
  33. module.exports = RequireIncludeDependency;