MCPcopy
hub / github.com/vitejs/vite / resolve

Function resolve

packages/vite/src/node/plugins/css.ts:1556–1590  ·  packages/vite/src/node/plugins/css.ts::resolve
(id, basedir, _importOptions, atRule)

Source from the content-addressed store, hash-verified

1554 postcssPlugins.unshift(
1555 (await importPostcssImport()).default({
1556 async resolve(id, basedir, _importOptions, atRule) {
1557 const publicFile = checkPublicFile(
1558 id,
1559 environment.getTopLevelConfig(),
1560 )
1561 if (publicFile) {
1562 return publicFile
1563 }
1564
1565 const resolved = await atImportResolvers.css(
1566 environment,
1567 id,
1568 class="cm">// The `source` is only absent for an `@import` injected by another plugin
1569 class="cm">// (a node with no source), in which case the resolver falls back to
1570 class="cm">// the project root.
1571 atRule.source?.input.file,
1572 )
1573
1574 if (resolved) {
1575 return path.resolve(resolved)
1576 }
1577
1578 class="cm">// postcss-import falls back to `resolve` dep if this is unresolved,
1579 class="cm">// but we've shimmed to remove the `resolve` dep to cut on bundle size.
1580 class="cm">// warn here to provide a better error message.
1581 if (!path.isAbsolute(id)) {
1582 environment.logger.error(
1583 colors.red(
1584 `Unable to resolve \`@import class="st">"${id}"\` from ${basedir}`,
1585 ),
1586 )
1587 }
1588
1589 return id
1590 },
1591 async load(id) {
1592 const code = await fs.promises.readFile(id, class="st">'utf-8')
1593 const lang = CSS_LANGS_RE.exec(id)?.[1] as CssLang | undefined

Callers 15

transformDynamicImportFunction · 0.70
resolverFunction · 0.70
handlerFunction · 0.70
runFunction · 0.50
runInlinedModuleMethod · 0.50
waitForWatcherFunction · 0.50
resolvePathFunction · 0.50
execAsyncFunction · 0.50
createServerCloseFnFunction · 0.50

Calls 8

checkPublicFileFunction · 0.90
getCssResolversKeysFunction · 0.85
getAtImportResolversFunction · 0.85
resolverFunction · 0.85
getTopLevelConfigMethod · 0.80
addMethod · 0.80
resolveMethod · 0.65
errorMethod · 0.65

Tested by 13

runFunction · 0.40
runInlinedModuleMethod · 0.40
waitForWatcherFunction · 0.40
resolvePathFunction · 0.40
configureServerFunction · 0.40
createSimpleServerFunction · 0.40
[Symbol.asyncDispose]Function · 0.40
fixtureFunction · 0.40
buildProjectFunction · 0.40
handleHotUpdateFunction · 0.40
hotUpdateFunction · 0.40
runFunction · 0.40