vite-plugin.ts — astro Source File
Architecture documentation for vite-plugin.ts, a typescript file in the astro codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f79d9e6e_0575_c2b8_506e_ddbc799b5f07["vite-plugin.ts"] 8651c206_171a_4a48_b04b_b47f5573b5da["../prerender/utils.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 8651c206_171a_4a48_b04b_b47f5573b5da e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> e9b74c5a_8d34_34a7_e196_5e41b87214aa 7f2f84c3_4040_d9fe_10d5_3b6ae522a328["../build/add-rollup-input.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 7f2f84c3_4040_d9fe_10d5_3b6ae522a328 1ddffc51_ee9d_5b0c_968e_331983e95ff4["../core/build/internal.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 1ddffc51_ee9d_5b0c_968e_331983e95ff4 e099eff3_3f90_76ac_3751_a9ff5a6b8f25["../../core/build/types.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> e099eff3_3f90_76ac_3751_a9ff5a6b8f25 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b 8df634da_0f30_1e1f_1314_2439b0c9baab["../core/errors/errors-data.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 8df634da_0f30_1e1f_1314_2439b0c9baab ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9 a370a45c_02f1_30de_445d_47ee08d095a2["../core/viteUtils.js"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> a370a45c_02f1_30de_445d_47ee08d095a2 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] f79d9e6e_0575_c2b8_506e_ddbc799b5f07 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 style f79d9e6e_0575_c2b8_506e_ddbc799b5f07 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { Plugin as VitePlugin } from 'vite';
import { getServerOutputDirectory } from '../../prerender/utils.js';
import type { AstroSettings } from '../../types/astro.js';
import { addRollupInput } from '../build/add-rollup-input.js';
import type { BuildInternals } from '../build/internal.js';
import type { StaticBuildOptions } from '../build/types.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES, MIDDLEWARE_PATH_SEGMENT_NAME } from '../constants.js';
import { MissingMiddlewareForInternationalization } from '../errors/errors-data.js';
import { AstroError } from '../errors/index.js';
import { normalizePath } from '../viteUtils.js';
// This module name is used in Cloudflare's optmizedDeps configuration,
// if th name changes that needs to be updated as well.
export const MIDDLEWARE_MODULE_ID = 'virtual:astro:middleware';
const MIDDLEWARE_RESOLVED_MODULE_ID = '\0' + MIDDLEWARE_MODULE_ID;
const NOOP_MIDDLEWARE = '\0noop-middleware';
export function vitePluginMiddleware({ settings }: { settings: AstroSettings }): VitePlugin {
let resolvedMiddlewareId: string | undefined = undefined;
const hasIntegrationMiddleware =
settings.middlewares.pre.length > 0 || settings.middlewares.post.length > 0;
let userMiddlewareIsPresent = false;
return {
name: '@astro/plugin-middleware',
applyToEnvironment(environment) {
return (
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr ||
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.astro ||
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender
);
},
resolveId: {
filter: {
id: new RegExp(`^${MIDDLEWARE_MODULE_ID}$`),
},
async handler() {
const middlewareId = await this.resolve(
`${decodeURI(settings.config.srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`,
);
userMiddlewareIsPresent = !!middlewareId;
if (middlewareId) {
resolvedMiddlewareId = middlewareId.id;
return MIDDLEWARE_RESOLVED_MODULE_ID;
} else if (hasIntegrationMiddleware) {
return MIDDLEWARE_RESOLVED_MODULE_ID;
} else {
return NOOP_MIDDLEWARE;
}
},
},
load: {
filter: {
id: new RegExp(`^(${NOOP_MIDDLEWARE}|${MIDDLEWARE_RESOLVED_MODULE_ID})$`),
},
async handler(id) {
if (id === NOOP_MIDDLEWARE) {
if (!userMiddlewareIsPresent && settings.config.i18n?.routing === 'manual') {
throw new AstroError(MissingMiddlewareForInternationalization);
}
// ... (91 more lines)
Domain
Subdomains
Dependencies
- ../../core/build/types.js
- ../build/add-rollup-input.js
- ../core/build/internal.js
- ../core/constants.js
- ../core/errors/errors-data.js
- ../core/errors/index.js
- ../core/viteUtils.js
- ../prerender/utils.js
- ../types/astro.js
- vite
Source
Frequently Asked Questions
What does vite-plugin.ts do?
vite-plugin.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in vite-plugin.ts?
vite-plugin.ts defines 3 function(s): createMiddlewareImports, vitePluginMiddleware, vitePluginMiddlewareBuild.
What does vite-plugin.ts depend on?
vite-plugin.ts imports 10 module(s): ../../core/build/types.js, ../build/add-rollup-input.js, ../core/build/internal.js, ../core/constants.js, ../core/errors/errors-data.js, ../core/errors/index.js, ../core/viteUtils.js, ../prerender/utils.js, and 2 more.
Where is vite-plugin.ts in the architecture?
vite-plugin.ts is located at packages/astro/src/core/middleware/vite-plugin.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/astro/src/core/middleware).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free