include.js 1.2 KB

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.pitch = void 0;
  4. const loaderUtils = require('loader-utils');
  5. function pitch(remainingRequest) {
  6. const { globals = undefined, pre = [], post = [] } = loaderUtils.getOptions(this) || {};
  7. // HACK: NamedModulesPlugin overwrites existing modules when requesting the same module via
  8. // different loaders, so we need to circumvent this by appending a suffix to make the name unique
  9. // See https://github.com/webpack/webpack/issues/4613#issuecomment-325178346 for details
  10. if (this._module && this._module.userRequest) {
  11. this._module.userRequest = `include-loader!${this._module.userRequest}`;
  12. }
  13. return [
  14. ...(globals
  15. ? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
  16. : []),
  17. ...pre.map((include) => `require(${loaderUtils.stringifyRequest(this, include)});`),
  18. `module.exports = require(${loaderUtils.stringifyRequest(this, `!!${remainingRequest}`)});`,
  19. ...post.map((include) => `require(${loaderUtils.stringifyRequest(this, include)});`),
  20. ].join('\n');
  21. }
  22. exports.pitch = pitch;
  23. ;