index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.warmup = exports.pitch = undefined;
  6. var _loaderUtils = require('loader-utils');
  7. var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
  8. var _workerPools = require('./workerPools');
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function pitch() {
  11. const options = _loaderUtils2.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. resolve: this.resolve,
  30. target: this.target,
  31. minimize: this.minimize,
  32. resourceQuery: this.resourceQuery,
  33. optionsContext: this.rootContext || this.options.context
  34. }, (err, r) => {
  35. if (r) {
  36. r.fileDependencies.forEach(d => this.addDependency(d));
  37. r.contextDependencies.forEach(d => this.addContextDependency(d));
  38. }
  39. if (err) {
  40. callback(err);
  41. return;
  42. }
  43. callback(null, ...r.result);
  44. });
  45. }
  46. function warmup(options, requires) {
  47. const workerPool = (0, _workerPools.getPool)(options);
  48. workerPool.warmup(requires);
  49. }
  50. exports.pitch = pitch;
  51. exports.warmup = warmup; // eslint-disable-line import/prefer-default-export