createVite() — astro Function Reference
Architecture documentation for the createVite() function in create-vite.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 156b640b_04f8_ebda_901f_2b1e9a0418aa["createVite()"] 60b1393e_9046_7d4d_1df5_b46cd58358d1["create-vite.ts"] 156b640b_04f8_ebda_901f_2b1e9a0418aa -->|defined in| 60b1393e_9046_7d4d_1df5_b46cd58358d1 1030c3db_a263_4ec6_e9f7_5814d88d569f["isCommonNotAstro()"] 156b640b_04f8_ebda_901f_2b1e9a0418aa -->|calls| 1030c3db_a263_4ec6_e9f7_5814d88d569f 1f6051ba_36ec_90fe_d715_13d70976bc15["stringifyForDefine()"] 156b640b_04f8_ebda_901f_2b1e9a0418aa -->|calls| 1f6051ba_36ec_90fe_d715_13d70976bc15 style 156b640b_04f8_ebda_901f_2b1e9a0418aa fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/create-vite.ts lines 72–276
export async function createVite(
commandConfig: vite.InlineConfig,
{ settings, logger, mode, command, fs = nodeFs, sync, routesList }: CreateViteOptions,
): Promise<vite.InlineConfig> {
const astroPkgsConfig = await crawlFrameworkPkgs({
root: fileURLToPath(settings.config.root),
isBuild: command === 'build',
viteUserConfig: settings.config.vite,
isFrameworkPkgByJson(pkgJson) {
// Certain packages will trigger the checks below, but need to be external. A common example are SSR adapters
// for node-based platforms, as we need to control the order of the import paths to make sure polyfills are applied in time.
if (pkgJson?.astro?.external === true) {
return false;
}
return (
// Attempt: package relies on `astro`. ✅ Definitely an Astro package
pkgJson.peerDependencies?.astro ||
pkgJson.dependencies?.astro ||
// Attempt: package is tagged with `astro` or `astro-component`. ✅ Likely a community package
pkgJson.keywords?.includes('astro') ||
pkgJson.keywords?.includes('astro-component') ||
// Attempt: package is named `astro-something` or `@scope/astro-something`. ✅ Likely a community package
/^(?:@[^/]+\/)?astro-/.test(pkgJson.name)
);
},
isFrameworkPkgByName(pkgName) {
const isNotAstroPkg = isCommonNotAstro(pkgName);
if (isNotAstroPkg) {
return false;
} else {
return undefined;
}
},
});
const envLoader = createEnvLoader({
mode,
config: settings.config,
});
// Start with the Vite configuration that Astro core needs
const commonConfig: vite.InlineConfig = {
// Tell Vite not to combine config from vite.config.js with our provided inline config
configFile: false,
mode,
cacheDir: fileURLToPath(new URL('./node_modules/.vite/', settings.config.root)), // using local caches allows Astro to be used in monorepos, etc.
clearScreen: false, // we want to control the output, not Vite
customLogger: createViteLogger(logger, settings.config.vite.logLevel),
appType: 'custom',
plugins: [
serializedManifestPlugin({ settings, command, sync }),
vitePluginRenderers({ settings }),
vitePluginStaticPaths(),
await astroPluginRoutes({ routesList, settings, logger, fsMod: fs, command }),
astroVirtualManifestPlugin(),
vitePluginEnvironment({ settings, astroPkgsConfig, command }),
pluginPage({ routesList }),
pluginPages({ routesList }),
configAliasVitePlugin({ settings }),
astroLoadFallbackPlugin({ fs, root: settings.config.root }),
astroVitePlugin({ settings, logger }),
astroScriptsPlugin({ settings }),
// The server plugin is for dev only and having it run during the build causes
// the build to run very slow as the filewatcher is triggered often.
vitePluginApp(),
command === 'dev' && vitePluginAstroServer({ settings, logger }),
command === 'dev' && vitePluginAstroServerClient(),
astroDevCssPlugin({ routesList, command }),
importMetaEnv({ envLoader }),
astroEnv({ settings, sync, envLoader }),
vitePluginAdapterConfig(settings),
markdownVitePlugin({ settings, logger }),
htmlVitePlugin(),
astroIntegrationsContainerPlugin({ settings, logger }),
astroScriptsPageSSRPlugin({ settings }),
astroHeadPlugin(),
astroContentVirtualModPlugin({ fs, settings }),
astroContentImportPlugin({ fs, settings, logger }),
astroContentAssetPropagationPlugin({ settings }),
vitePluginMiddleware({ settings }),
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does createVite() do?
createVite() is a function in the astro codebase, defined in packages/astro/src/core/create-vite.ts.
Where is createVite() defined?
createVite() is defined in packages/astro/src/core/create-vite.ts at line 72.
What does createVite() call?
createVite() calls 2 function(s): isCommonNotAstro, stringifyForDefine.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free