Skip to main content
The build() function builds your Astro site for deployment. By default, this generates static files in a dist/ directory. If SSR is enabled, it generates the necessary server files.
The JavaScript API is experimental and may change in future releases.

Import

Signature

Parameters

inlineConfig

AstroInlineConfig
required
Configuration object for your Astro project. Supports all options from astro.config.mjs.
string
The root directory of your Astro project. Defaults to the current working directory.
'debug' | 'info' | 'warn' | 'error' | 'silent'
default:"'info'"
Controls the verbosity of logging output during the build.
string
Your final deployed URL. Used for generating sitemaps and canonical URLs.
string
default:"'/'"
The base path to deploy to. All pages and assets will use this as a prefix.
string
default:"'./dist'"
The directory where build output will be written.
string
default:"'production'"
The build mode. Affects environment variable loading.
boolean
default:"false"
Clear the content layer cache before building, forcing a full rebuild.

options

BuildOptions
Additional build-specific options.
boolean
default:"false"
Output a development-based build similar to astro dev. Useful for testing build-only issues with additional debugging information.
boolean
default:"true"
Teardown the compiler WASM instance after build. Improves performance for single builds, but may hurt performance when building multiple times in succession (e.g., during tests).

Return Value

Returns a Promise<void> that resolves when the build completes successfully, or rejects with an error if the build fails.

Examples

Basic Build

Custom Configuration

Development Build

Create a build with development-like output for debugging:

Multiple Builds

When building multiple projects, disable compiler teardown for better performance:

With Error Handling

Force Clean Build

CI/CD Integration

  • dev() - Start the development server
  • preview() - Preview your production build
  • sync() - Generate TypeScript types