RequireIncludeDependency.js 1.1 KB

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