Prerequisites
Before running any commands, ensure you have installed project dependencies:package.json.
Development commands
Start development server
http://localhost:4321.
Features:
- Hot reloading when you edit files
- Fast refresh for
.astrocomponents - Instant feedback on syntax errors
- Automatic TypeScript type checking
The development server watches for file changes in
src/ and automatically updates your browser. No manual refresh needed.The
-- syntax passes arguments through npm to the underlying Astro command.Build commands
Production build
- Compiles all
.astrofiles to optimized HTML - Bundles and minifies JavaScript
- Optimizes CSS and removes unused styles
- Processes and optimizes images
- Generates the final static site in
./dist/
dist directory containing:
- Static HTML files for each page
- Optimized JavaScript bundles
- Minified CSS files
- Copied assets from
public/
Preview production build
./dist/ exactly as they would appear on a production server.
Use cases:
- Test production build before deployment
- Verify optimizations are working correctly
- Check that all links and assets resolve properly
- Validate responsive design at production speed
You must run
npm run build before using the preview command. The preview server only serves pre-built files.Astro CLI commands
Run Astro CLI directly
Get CLI help
Get CLI help
Add integrations
Add integrations
astro.config.mjs and installs required dependencies.Check for issues
Check for issues
- TypeScript type checking
- Accessibility checks in
.astrofiles - Validation of configuration files
View Astro info
View Astro info
- Astro version
- Node.js version
- Operating system
- Installed integrations
Sync type definitions
Sync type definitions
Create new files
Create new files
Command cheat sheet
Quick reference for all available commands:| Command | Action |
|---|---|
npm install | Install project dependencies |
npm run dev | Start development server at localhost:4321 |
npm run build | Build production site to ./dist/ |
npm run preview | Preview production build locally |
npm run astro | Run Astro CLI commands |
npm run astro -- --help | Display Astro CLI help |
npm run astro add [integration] | Add and configure an integration |
npm run astro check | Check project for issues |
npm run astro info | Display environment information |
npm run astro sync | Generate type definitions |
Development workflow
Here’s a typical development workflow using these commands:CI/CD integration
These commands integrate seamlessly into continuous integration pipelines:Most hosting platforms (Vercel, Netlify, Cloudflare Pages) automatically detect Astro projects and use the correct build command.
Troubleshooting commands
Clear cache and rebuild
If you encounter build issues, try clearing cached files:Debug build issues
Run the build with verbose logging:Check for outdated packages
Ensure you’re using compatible versions:Performance tips
Use development server for iteration
Use development server for iteration
The
dev command provides the fastest feedback loop. Only use build and preview when you need to test production-specific behavior.Leverage parallel builds
Leverage parallel builds
Astro automatically parallelizes builds across CPU cores. Ensure your build environment has adequate resources for optimal performance.
Monitor build output size
Monitor build output size
After running
npm run build, check the size of your dist/ directory. Astro displays bundle sizes in the build output.Use astro check in pre-commit hooks
Use astro check in pre-commit hooks
Add
npm run astro check to your Git pre-commit hooks to catch errors before they reach CI/CD.Next steps
- Learn about configuration options for customizing build behavior
- Explore Astro CLI documentation for advanced commands
- Set up deployment automation for your preferred hosting platform