Available Functions
The Astro JavaScript API exports the following functions:build()
Build your Astro project for production
dev()
Start the Astro development server
preview()
Preview your production build locally
sync()
Generate TypeScript types for your project
Installation
Install Astro in your project:Basic Usage
Import the functions you need from theastro package:
Configuration
All API functions accept anAstroInlineConfig object that allows you to configure Astro programmatically. This object supports all the same options as astro.config.mjs.
Common Options
These options are available for all API functions:string
default:"process.cwd()"
The root directory of your Astro project. Can be an absolute path or relative to the current working directory.
'debug' | 'info' | 'warn' | 'error' | 'silent'
default:"'info'"
The logging level for Astro’s output.
string
default:"'production'"
The mode to run Astro in. This affects environment variable loading and other build-time behavior.
string
Your deployed site URL. Used for generating sitemaps and canonical URLs.
string
default:"'/'"
The base path where your site is deployed.
string
default:"'./dist'"
The directory where build output is written.
boolean
default:"false"
Force a clean build by clearing the content layer cache.