getStylesForURL() — astro Function Reference
Architecture documentation for the getStylesForURL() function in vite-plugin-content-assets.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD b4620bc6_fff6_cf0a_dfd0_21b3625d5f6f["getStylesForURL()"] 7a46444b_6633_b7e5_30ac_f5b4aa6a43ff["vite-plugin-content-assets.ts"] b4620bc6_fff6_cf0a_dfd0_21b3625d5f6f -->|defined in| 7a46444b_6633_b7e5_30ac_f5b4aa6a43ff 121a0a31_a45b_2d2b_1133_094c7123cad8["astroContentAssetPropagationPlugin()"] 121a0a31_a45b_2d2b_1133_094c7123cad8 -->|calls| b4620bc6_fff6_cf0a_dfd0_21b3625d5f6f style b4620bc6_fff6_cf0a_dfd0_21b3625d5f6f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/vite-plugin-content-assets.ts lines 148–203
async function getStylesForURL(
filePath: string,
environment: RunnableDevEnvironment,
): Promise<{ urls: Set<string>; styles: ImportedDevStyle[]; crawledFiles: Set<string> }> {
const importedCssUrls = new Set<string>();
// Map of url to injected style object. Use a `url` key to deduplicate styles
const importedStylesMap = new Map<string, ImportedDevStyle>();
const crawledFiles = new Set<string>();
for await (const importedModule of crawlGraph(environment, filePath, false)) {
if (importedModule.file) {
crawledFiles.add(importedModule.file);
}
if (isBuildableCSSRequest(importedModule.url)) {
// In dev, we inline all styles if possible
let css = '';
// If this is a plain CSS module, the default export should be a string
if (typeof importedModule.ssrModule?.default === 'string') {
css = importedModule.ssrModule.default;
}
// Else try to load it
else {
let modId = importedModule.url;
// Mark url with ?inline so Vite will return the CSS as plain string, even for CSS modules
if (!INLINE_QUERY_REGEX.test(importedModule.url)) {
if (importedModule.url.includes('?')) {
modId = importedModule.url.replace('?', '?inline&');
} else {
modId += '?inline';
}
}
try {
// The SSR module is possibly not loaded. Load it if it's null.
const ssrModule = await environment.runner.import(modId);
css = ssrModule.default;
} catch {
// The module may not be inline-able, e.g. SCSS partials. Skip it as it may already
// be inlined into other modules if it happens to be in the graph.
continue;
}
}
importedStylesMap.set(importedModule.url, {
id: wrapId(importedModule.id ?? importedModule.url),
url: wrapId(importedModule.url),
content: css,
});
}
}
return {
urls: importedCssUrls,
styles: [...importedStylesMap.values()],
crawledFiles,
};
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getStylesForURL() do?
getStylesForURL() is a function in the astro codebase, defined in packages/astro/src/content/vite-plugin-content-assets.ts.
Where is getStylesForURL() defined?
getStylesForURL() is defined in packages/astro/src/content/vite-plugin-content-assets.ts at line 148.
What calls getStylesForURL()?
getStylesForURL() is called by 1 function(s): astroContentAssetPropagationPlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free