utils.js 630 B

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