index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.pitch = pitch;
  6. exports.warmup = warmup;
  7. var _loaderUtils = _interopRequireDefault(require("loader-utils"));
  8. var _workerPools = require("./workerPools");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function pitch() {
  11. const options = _loaderUtils.default.getOptions(this);
  12. const workerPool = (0, _workerPools.getPool)(options);
  13. if (!workerPool.isAbleToRun()) {
  14. return;
  15. }
  16. const callback = this.async();
  17. workerPool.run({
  18. loaders: this.loaders.slice(this.loaderIndex + 1).map(l => {
  19. return {
  20. loader: l.path,
  21. options: l.options,
  22. ident: l.ident
  23. };
  24. }),
  25. resource: this.resourcePath + (this.resourceQuery || ''),
  26. sourceMap: this.sourceMap,
  27. emitError: this.emitError,
  28. emitWarning: this.emitWarning,
  29. loadModule: this.loadModule,
  30. resolve: this.resolve,
  31. getResolve: this.getResolve,
  32. target: this.target,
  33. minimize: this.minimize,
  34. resourceQuery: this.resourceQuery,
  35. optionsContext: this.rootContext || this.options.context,
  36. rootContext: this.rootContext
  37. }, (err, r) => {
  38. if (r) {
  39. r.fileDependencies.forEach(d => this.addDependency(d));
  40. r.contextDependencies.forEach(d => this.addContextDependency(d));
  41. r.missingDependencies.forEach(d => this.addMissingDependency(d));
  42. r.buildDependencies.forEach(d => // Compatibility with webpack v4
  43. this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d));
  44. }
  45. if (err) {
  46. callback(err);
  47. return;
  48. }
  49. callback(null, ...r.result);
  50. });
  51. }
  52. function warmup(options, requires) {
  53. const workerPool = (0, _workerPools.getPool)(options);
  54. workerPool.warmup(requires);
  55. } // eslint-disable-line import/prefer-default-export