is-module-should-be-extracted.js 948 B

1234567891011121314151617181920212223242526272829303132333435
  1. const defaults = require('../config');
  2. const normalizeRule = require('./normalize-rule');
  3. const spriteLoaderPath = require.resolve('../loader');
  4. /**
  5. * @param {NormalModule} module
  6. * @return {boolean}
  7. */
  8. function isModuleShouldBeExtracted(module) {
  9. const { request, issuer, loaders } = module;
  10. let rule = null;
  11. if (Array.isArray(loaders) && loaders.length > 0) {
  12. // Find loader rule
  13. rule = loaders.map(normalizeRule).find(data => data.loader === spriteLoaderPath);
  14. }
  15. let issuerResource = null;
  16. if (issuer) {
  17. // webpack 1 compat
  18. issuerResource = typeof issuer === 'string' ? issuer : issuer.resource;
  19. }
  20. if (typeof request === 'string' && (!request.includes(spriteLoaderPath) || !rule)) {
  21. return false;
  22. }
  23. return !!(
  24. (issuer && defaults.EXTRACTABLE_MODULE_ISSUER_PATTERN.test(issuerResource)) ||
  25. (rule && rule.options && rule.options.extract)
  26. );
  27. }
  28. module.exports = isModuleShouldBeExtracted;