utils.js 729 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getModulePathParts = getModulePathParts;
  6. const MULTI_MODULE_REGEXP = /^multi /u;
  7. function getModulePathParts(moduleData) {
  8. if (MULTI_MODULE_REGEXP.test(moduleData.identifier)) {
  9. return [moduleData.identifier];
  10. }
  11. const loaders = moduleData.name.split('!'); // Removing loaders from module path: they're joined by `!` and the last part is a raw module path
  12. const parsedPath = loaders[loaders.length - 1] // Splitting module path into parts
  13. .split('/') // Removing first `.`
  14. .slice(1) // Replacing `~` with `node_modules`
  15. .map(part => part === '~' ? 'node_modules' : part);
  16. return parsedPath.length ? parsedPath : null;
  17. }