index.ts — astro Source File
Architecture documentation for index.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1ab33465_d174_4d12_56c8_8d8e7d679cb7["index.ts"] e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> e9b74c5a_8d34_34a7_e196_5e41b87214aa 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 15ae4600_b0d8_f6de_2dd1_ec911a90c4fc["vitefu"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> 15ae4600_b0d8_f6de_2dd1_ec911a90c4fc e64464d4_88a4_c7e2_f90f_758b06231bbe["tinyglobby"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> e64464d4_88a4_c7e2_f90f_758b06231bbe d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] 1ab33465_d174_4d12_56c8_8d8e7d679cb7 --> d9a92db9_c95e_9165_13ac_24b3d859d946 style 1ab33465_d174_4d12_56c8_8d8e7d679cb7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type * as vite from 'vite';
import type { AstroSettings } from '../types/astro.js';
import type { CrawlFrameworkPkgsResult } from 'vitefu';
import type { EnvironmentOptions } from 'vite';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../core/constants.js';
import { convertPathToPattern } from 'tinyglobby';
import { fileURLToPath } from 'node:url';
// These specifiers are usually dependencies written in CJS, but loaded through Vite's transform
// pipeline, which Vite doesn't support in development time. This hardcoded list temporarily
// fixes things until Vite can properly handle them, or when they support ESM.
const ONLY_DEV_EXTERNAL = [
// Imported by `@astrojs/prism` which exposes `<Prism/>` that is processed by Vite
'prismjs/components/index.js',
// Imported by `astro/assets` -> `packages/astro/src/core/logger/core.ts`
'string-width',
// Imported by `astro:transitions` -> packages/astro/src/runtime/server/transition.ts
'cssesc',
];
const ALWAYS_NOEXTERNAL = [
// This is only because Vite's native ESM doesn't resolve "exports" correctly.
'astro',
// Vite fails on nested `.astro` imports without bundling
'astro/components',
// Handle recommended nanostores. Only @nanostores/preact is required from our testing!
// Full explanation and related bug report: https://github.com/withastro/astro/pull/3667
'@nanostores/preact',
// fontsource packages are CSS that need to be processed
'@fontsource/*',
];
interface Payload {
command: 'dev' | 'build';
settings: AstroSettings;
astroPkgsConfig: CrawlFrameworkPkgsResult;
}
/**
* This plugin is responsible of setting up the environments of the vite server, such as
* dependencies, SSR, etc.
*
*/
export function vitePluginEnvironment({
command,
settings,
astroPkgsConfig,
}: Payload): vite.Plugin {
const srcDirPattern = convertPathToPattern(fileURLToPath(settings.config.srcDir));
return {
name: 'astro:environment',
configEnvironment(environmentName, _options): EnvironmentOptions {
const finalEnvironmentOptions: EnvironmentOptions = {
optimizeDeps: {
include: [],
exclude: [],
},
resolve: {
// Astro imports in third-party packages should use the same version as root
dedupe: ['astro'],
},
};
if (
environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.ssr ||
environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.astro ||
environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.prerender ||
environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.client
) {
if (_options.resolve?.noExternal !== true) {
finalEnvironmentOptions.resolve!.noExternal = [
...ALWAYS_NOEXTERNAL,
...astroPkgsConfig.ssr.noExternal,
];
finalEnvironmentOptions.resolve!.external = [
...(command === 'dev' ? ONLY_DEV_EXTERNAL : []),
...astroPkgsConfig.ssr.external,
];
}
if (_options.optimizeDeps?.noDiscovery === false) {
finalEnvironmentOptions.optimizeDeps = {
entries: [`${srcDirPattern}**/*.{jsx,tsx,vue,svelte,html,astro}`],
include: [],
exclude: ['node-fetch'],
};
}
}
if (environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
finalEnvironmentOptions.optimizeDeps = {
include: [
// For the dev toolbar
'astro > html-escaper',
],
exclude: ['astro:*', 'virtual:astro:*'],
// Astro files can't be rendered on the client
entries: [`${srcDirPattern}**/*.{jsx,tsx,vue,svelte,html}`],
};
}
return finalEnvironmentOptions;
},
};
}
Domain
Subdomains
Functions
Types
Dependencies
- ../core/constants.js
- ../types/astro.js
- node:url
- tinyglobby
- vite
- vitefu
Source
Frequently Asked Questions
What does index.ts do?
index.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in index.ts?
index.ts defines 1 function(s): vitePluginEnvironment.
What does index.ts depend on?
index.ts imports 6 module(s): ../core/constants.js, ../types/astro.js, node:url, tinyglobby, vite, vitefu.
Where is index.ts in the architecture?
index.ts is located at packages/astro/src/vite-plugin-environment/index.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-environment).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free