> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/withastro/astro/llms.txt
> Use this file to discover all available pages before exploring further.

# build()

> Build your Astro site for production deployment

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.

<Warning>
  The JavaScript API is experimental and may change in future releases.
</Warning>

## Import

```javascript theme={null}
import { build } from 'astro';
```

## Signature

```typescript theme={null}
function build(
  inlineConfig: AstroInlineConfig,
  options?: BuildOptions
): Promise<void>
```

## Parameters

### inlineConfig

<ParamField path="inlineConfig" type="AstroInlineConfig" required>
  Configuration object for your Astro project. Supports all options from `astro.config.mjs`.
</ParamField>

<ParamField path="inlineConfig.root" type="string">
  The root directory of your Astro project. Defaults to the current working directory.
</ParamField>

<ParamField path="inlineConfig.logLevel" type="'debug' | 'info' | 'warn' | 'error' | 'silent'" default="'info'">
  Controls the verbosity of logging output during the build.
</ParamField>

<ParamField path="inlineConfig.site" type="string">
  Your final deployed URL. Used for generating sitemaps and canonical URLs.
</ParamField>

<ParamField path="inlineConfig.base" type="string" default="'/'">
  The base path to deploy to. All pages and assets will use this as a prefix.
</ParamField>

<ParamField path="inlineConfig.outDir" type="string" default="'./dist'">
  The directory where build output will be written.
</ParamField>

<ParamField path="inlineConfig.mode" type="string" default="'production'">
  The build mode. Affects environment variable loading.
</ParamField>

<ParamField path="inlineConfig.force" type="boolean" default="false">
  Clear the content layer cache before building, forcing a full rebuild.
</ParamField>

### options

<ParamField path="options" type="BuildOptions">
  Additional build-specific options.
</ParamField>

<ParamField path="options.devOutput" type="boolean" default="false">
  Output a development-based build similar to `astro dev`. Useful for testing build-only issues with additional debugging information.
</ParamField>

<ParamField path="options.teardownCompiler" type="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).
</ParamField>

## 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

```javascript theme={null}
import { build } from 'astro';

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

### Custom Configuration

```javascript theme={null}
import { build } from 'astro';

await build({
  root: './my-project',
  site: 'https://example.com',
  base: '/blog',
  outDir: './dist/blog',
  logLevel: 'info',
});
```

### Development Build

Create a build with development-like output for debugging:

```javascript theme={null}
import { build } from 'astro';

await build(
  {
    root: './my-project',
    logLevel: 'debug',
  },
  {
    devOutput: true,
  }
);
```

### Multiple Builds

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

```javascript theme={null}
import { build } from 'astro';

const projects = ['./site-1', './site-2', './site-3'];

for (let i = 0; i < projects.length; i++) {
  await build(
    { root: projects[i] },
    {
      // Don't teardown compiler until the last build
      teardownCompiler: i === projects.length - 1,
    }
  );
}
```

### With Error Handling

```javascript theme={null}
import { build } from 'astro';

try {
  await build({
    root: './my-project',
    site: 'https://example.com',
  });
  console.log('Build completed successfully!');
} catch (error) {
  console.error('Build failed:', error);
  process.exit(1);
}
```

### Force Clean Build

```javascript theme={null}
import { build } from 'astro';

await build({
  root: './my-project',
  force: true, // Clear content layer cache
});
```

### CI/CD Integration

```javascript theme={null}
import { build } from 'astro';

async function buildForProduction() {
  const startTime = Date.now();

  await build({
    root: process.env.PROJECT_ROOT || '.',
    site: process.env.SITE_URL,
    base: process.env.BASE_PATH || '/',
    outDir: process.env.OUT_DIR || './dist',
    logLevel: process.env.CI ? 'info' : 'debug',
  });

  const duration = ((Date.now() - startTime) / 1000).toFixed(2);
  console.log(`Build completed in ${duration}s`);
}

buildForProduction().catch((error) => {
  console.error('Build failed:', error);
  process.exit(1);
});
```

## Related

* [dev()](/api/dev) - Start the development server
* [preview()](/api/preview) - Preview your production build
* [sync()](/api/sync) - Generate TypeScript types
