CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-astro

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli-and-build.mddocs/

CLI and Build Commands

Core CLI commands and programmatic APIs for building, developing, previewing, and managing Astro projects.

Capabilities

Build Command

Builds the Astro project for production deployment.

/**
 * Builds the Astro project for production
 * @param inlineConfig - Configuration options for the build
 * @param options - Build-specific options
 * @returns Promise that resolves when build completes
 */
function build(inlineConfig: AstroInlineConfig, options?: BuildOptions): Promise<void>;
import { build } from 'astro';

await build({
  root: './my-project',
  mode: 'production',
});

Development Server

Starts the Astro development server with hot module reloading.

/**
 * Starts the development server
 * @returns Promise that resolves with DevServer instance when server starts
 */
function dev(inlineConfig: AstroInlineConfig): Promise<DevServer>;

interface DevServer {
  address: AddressInfo;
  handle: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
  watcher: vite.FSWatcher;
  stop(): Promise<void>;
}
import { dev } from 'astro';

const server = await dev({
  root: './my-project',
  server: {
    port: 3000,
    host: true,
  },
});

await server.stop();

Preview Server

Previews the production build locally before deployment.

/**
 * Previews the production build
 * @returns Promise that resolves with PreviewServer instance when server starts
 */
function preview(inlineConfig: AstroInlineConfig): Promise<PreviewServer>;
import { preview } from 'astro';

await preview({
  root: './my-project',
  server: {
    port: 4321,
  },
});

Type Generation (Sync)

Generates TypeScript type definitions for Astro modules.

/**
 * Generates TypeScript types for Astro modules (experimental)
 * @returns Promise that resolves when sync completes
 */
function sync(inlineConfig: AstroInlineConfig): Promise<void>;
import { sync } from 'astro';

await sync({
  root: './my-project',
});

Types

BuildOptions

Build-specific configuration options.

interface BuildOptions {
  /**
   * Output a development-based build
   * @default false
   */
  devOutput?: boolean;

  /**
   * Teardown the compiler WASM instance after build
   * @default true
   */
  teardownCompiler?: boolean;
}

PreviewServer

Server instance returned from the preview command.

interface PreviewServer {
  host?: string;
  port: number;
  stop(): Promise<void>;
  closed(): Promise<void>;
}

AstroInlineConfig

Configuration object for programmatic API calls.

interface AstroInlineConfig {
  /**
   * Project root directory
   * @default process.cwd()
   */
  root?: string | URL;

  /**
   * Build mode
   * @default 'development' for dev, 'production' for build
   */
  mode?: 'development' | 'production';

  server?: {
    port?: number;
    host?: string | boolean;
    open?: boolean | string;
  };

  site?: string;
  base?: string;
  output?: 'static' | 'server';
  trailingSlash?: 'always' | 'never' | 'ignore';
  adapter?: AstroAdapter;
  integrations?: AstroIntegration[];
  vite?: ViteUserConfig;
}

CLI Commands

# Development server
astro dev [root]
  --port <number>        Port to run dev server on (default: 4321)
  --host [address]       Network address to listen on
  --open                 Open browser on server start
  --mode <mode>          Build mode (default: development)
  --force                Force rebuild
  --allowed-hosts <hosts> Allowed hosts for CORS

# Production build
astro build [root]
  --outDir <directory>   Output directory (default: dist)
  --mode <mode>          Build mode (default: production)
  --devOutput            Output development-style build
  --force                Force rebuild

# Preview production build
astro preview [root]
  --port <number>        Port to run preview server on (default: 4321)
  --host [address]       Network address to listen on
  --open                 Open browser on server start
  --allowed-hosts <hosts> Allowed hosts for CORS

# Type generation
astro sync [root]
  --force                Force regeneration

# Add integrations
astro add <integration>

# Type checking
astro check

# Show environment info
astro info

# Configure telemetry
astro telemetry [enable|disable|reset]

# Configure preferences
astro preferences list
astro preferences set <key> <value>
astro preferences reset <key>

Environment Variables

Astro respects several environment variables:

  • NODE_ENV - Set to 'production' or 'development'
  • ASTRO_TELEMETRY_DISABLED - Set to '1' to disable telemetry
  • ASTRO_CONFIG_FILE - Custom config file location
  • PUBLIC_* - Environment variables prefixed with PUBLIC_ are available to client-side code

Common Issues

  • Port conflicts: If the default port (4321) is in use, specify a different port with --port or in your config.
  • Build failures: Run with --force to clear cache and rebuild from scratch.
  • Type sync issues: Run astro sync manually to regenerate types if IDE completion is stale.

docs

assets.md

cli-and-build.md

configuration.md

container.md

content-collections.md

content-loaders.md

dev-toolbar.md

environment.md

i18n.md

index.md

integrations.md

middleware.md

server-actions.md

ssr-and-app.md

transitions.md

tile.json