Skip to content

Function: parseModuleId() ​

  • Exported from: rolldown/utils
  • Type: (id: string) => { attributes: Record<string, string>; rawId: string; }

Splits a module id into the raw id and the import attributes it was built from.

An id that only looks like it has attributes, e.g. virtual?attributes=foo, is returned as the raw id with no attributes, because only a suffix that stringifyModuleId produces exactly is accepted.

Parameters ​

id ​

string

Returns ​

{ attributes: Record<string, string>; rawId: string; }

attributes ​

  • Type: Record<string, string>

rawId ​

  • Type: string

Example ​

js
parseModuleId('/src/a.json?attributes=%7B%22type%22%3A%22json%22%7D');
// → { rawId: '/src/a.json', attributes: { type: 'json' } }
parseModuleId('/src/a.js?raw');
// → { rawId: '/src/a.js?raw', attributes: {} }

Was this page helpful?