astroContentImportPlugin() — astro Function Reference
Architecture documentation for the astroContentImportPlugin() function in vite-plugin-content-imports.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 06cd4177_9728_08c0_fa43_2385e28cbaf4["astroContentImportPlugin()"] 157f6669_1b64_2b6d_ca39_b0f784c87ad2["vite-plugin-content-imports.ts"] 06cd4177_9728_08c0_fa43_2385e28cbaf4 -->|defined in| 157f6669_1b64_2b6d_ca39_b0f784c87ad2 680890c8_1665_e25c_7957_e9303be73454["getDataEntryModule()"] 06cd4177_9728_08c0_fa43_2385e28cbaf4 -->|calls| 680890c8_1665_e25c_7957_e9303be73454 4e091873_0693_5420_b2f8_6752dc3df051["stringifyEntryData()"] 06cd4177_9728_08c0_fa43_2385e28cbaf4 -->|calls| 4e091873_0693_5420_b2f8_6752dc3df051 faee72c2_19cd_965a_76d9_c12bcc678122["getContentEntryModule()"] 06cd4177_9728_08c0_fa43_2385e28cbaf4 -->|calls| faee72c2_19cd_965a_76d9_c12bcc678122 cf9ce9b8_bf3a_bf89_be3d_c5390f14a54b["getContentRendererByViteId()"] 06cd4177_9728_08c0_fa43_2385e28cbaf4 -->|calls| cf9ce9b8_bf3a_bf89_be3d_c5390f14a54b style 06cd4177_9728_08c0_fa43_2385e28cbaf4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/vite-plugin-content-imports.ts lines 66–232
export function astroContentImportPlugin({
fs,
settings,
logger,
}: {
fs: typeof fsMod;
settings: AstroSettings;
logger: Logger;
}): Plugin[] {
const contentPaths = getContentPaths(
settings.config,
fs,
settings.config.legacy?.collectionsBackwardsCompat,
);
const contentEntryExts = getContentEntryExts(settings);
const dataEntryExts = getDataEntryExts(settings);
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
const dataEntryConfigByExt = getEntryConfigByExtMap(settings.dataEntryTypes);
const { contentDir } = contentPaths;
let shouldEmitFile = false;
let symlinks: Map<string, string>;
const plugins: Plugin[] = [
{
name: 'astro:content-imports',
config(_config, env) {
shouldEmitFile = env.command === 'build';
},
async buildStart() {
// Get symlinks once at build start
symlinks = await getSymlinkedContentCollections({ contentDir, logger, fs });
},
transform: {
filter: {
id: new RegExp(`(?:\\?|&)(?:${DATA_FLAG}|${CONTENT_FLAG})(?:&|=|$)`),
},
async handler(_, viteId) {
if (hasContentFlag(viteId, DATA_FLAG)) {
// By default, Vite will resolve symlinks to their targets. We need to reverse this for
// content entries, so we can get the path relative to the content directory.
const fileId = reverseSymlink({
entry: viteId.split('?')[0] ?? viteId,
contentDir,
symlinks,
});
// Data collections don't need to rely on the module cache.
// This cache only exists for the `render()` function specific to content.
const { id, data, collection, _internal } = await getDataEntryModule({
fileId,
entryConfigByExt: dataEntryConfigByExt,
contentDir,
config: settings.config,
fs,
pluginContext: this,
shouldEmitFile,
});
const code = `
export const id = ${JSON.stringify(id)};
export const collection = ${JSON.stringify(collection)};
export const data = ${stringifyEntryData(data, settings.buildOutput === 'server')};
export const _internal = {
type: 'data',
filePath: ${JSON.stringify(_internal.filePath)},
rawData: ${JSON.stringify(_internal.rawData)},
};
`;
return code;
} else if (hasContentFlag(viteId, CONTENT_FLAG)) {
const fileId = reverseSymlink({ entry: viteId.split('?')[0], contentDir, symlinks });
const { id, slug, collection, body, data, _internal } = await getContentEntryModule({
fileId,
entryConfigByExt: contentEntryConfigByExt,
contentDir,
config: settings.config,
fs,
pluginContext: this,
shouldEmitFile,
});
const code = `
Domain
Subdomains
Source
Frequently Asked Questions
What does astroContentImportPlugin() do?
astroContentImportPlugin() is a function in the astro codebase, defined in packages/astro/src/content/vite-plugin-content-imports.ts.
Where is astroContentImportPlugin() defined?
astroContentImportPlugin() is defined in packages/astro/src/content/vite-plugin-content-imports.ts at line 66.
What does astroContentImportPlugin() call?
astroContentImportPlugin() calls 4 function(s): getContentEntryModule, getContentRendererByViteId, getDataEntryModule, stringifyEntryData.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free