dev() — astro Function Reference
Architecture documentation for the dev() function in dev.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 328b54db_3f5e_f095_3a32_9cce5dc44cd7["dev()"] 84715425_98c7_454a_c767_8998ba6815e1["dev.ts"] 328b54db_3f5e_f095_3a32_9cce5dc44cd7 -->|defined in| 84715425_98c7_454a_c767_8998ba6815e1 style 328b54db_3f5e_f095_3a32_9cce5dc44cd7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/dev/dev.ts lines 37–150
export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevServer> {
ensureProcessNodeEnv('development');
const devStart = performance.now();
await telemetry.record([]);
// Create a container which sets up the Vite server.
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
const logger = restart.container.logger;
const currentVersion = process.env.PACKAGE_VERSION ?? '0.0.0';
const isPrerelease = currentVersion.includes('-');
if (!isPrerelease) {
try {
// Don't await this, we don't want to block the dev server from starting
shouldCheckForUpdates(restart.container.settings.preferences)
.then(async (shouldCheck) => {
if (shouldCheck) {
const version = await fetchLatestAstroVersion(restart.container.settings.preferences);
if (gt(version, currentVersion)) {
// Only update the latestAstroVersion if the latest version is greater than the current version, that way we don't need to check that again
// whenever we check for the latest version elsewhere
restart.container.settings.latestAstroVersion = version;
const sameMajor = major(version) === major(currentVersion);
const sameMinor = minor(version) === minor(currentVersion);
const patchDistance = patch(version) - patch(currentVersion);
if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) {
// Don't bother the user with a log if they're only a few patch versions behind
// We can still tell them in the dev toolbar, which has a more opt-in nature
return;
}
logger.warn(
'SKIP_FORMAT',
await msg.newVersionAvailable({
latestVersion: version,
}),
);
}
}
})
.catch(() => {});
} catch {
// Just ignore the error, we don't want to block the dev server from starting and this is just a nice-to-have feature
}
}
let store: MutableDataStore | undefined;
try {
const dataStoreFile = getDataStoreFile(restart.container.settings, true);
store = await MutableDataStore.fromFile(dataStoreFile);
} catch (err: any) {
logger.error('content', err.message);
}
if (!store) {
logger.error('content', 'Failed to create data store');
}
await attachContentServerListeners(restart.container);
const config = globalContentConfigObserver.get();
if (config.status === 'error') {
logger.error('content', config.error.message);
}
if (config.status === 'loaded' && store) {
const contentLayer = globalContentLayer.init({
settings: restart.container.settings,
logger,
watcher: restart.container.viteServer.watcher,
store,
});
contentLayer.watchContentConfig();
await contentLayer.sync();
} else {
logger.warn('content', 'Content config not loaded');
}
// Start listening to the port
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does dev() do?
dev() is a function in the astro codebase, defined in packages/astro/src/core/dev/dev.ts.
Where is dev() defined?
dev() is defined in packages/astro/src/core/dev/dev.ts at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free