The dev server lets you see your website live while you build it. The build process prepares your site to be fast and ready for visitors.
Dev server and build process in Astro
astro dev astro build
astro dev starts the development server with live reload.
astro build creates optimized files for production.
astro dev
astro build
This example shows the steps to use the dev server and build process in Astro. First, run astro dev to start live preview. After finishing your work, run astro build to prepare your site for publishing.
/*
Run in terminal:
1. astro dev
2. Make changes in your Astro files
3. See updates live in browser
Then:
4. astro build
5. Upload the 'dist' folder to your hosting
*/The dev server automatically reloads your browser when you save changes.
The build process optimizes images, CSS, and JavaScript for faster loading.
Always test your site with the dev server before building to catch errors early.
The dev server helps you see changes live while building your site.
The build process creates fast, optimized files for your website.
Use astro dev for development and astro build before publishing.
Practice
astro dev command in Astro?Solution
Step 1: Understand the role of
Theastro devastro devcommand runs a local server that watches your files and reloads the browser when you make changes.Step 2: Differentiate from build process
The build process (astro build) creates optimized files for publishing, not live updates.Final Answer:
To start a development server that shows live updates as you code -> Option AQuick Check:
Dev server = live updates [OK]
- Confusing dev server with build output
- Thinking
astro devcreates production files - Assuming
astro devinstalls packages
Solution
Step 1: Recall Astro build command
The commandastro buildis used to create optimized production files for deployment.Step 2: Verify other commands
astro start,astro run, andastro serveare not valid build commands in Astro.Final Answer:
astro build -> Option CQuick Check:
Build command = astro build [OK]
- Using
astro startinstead ofastro build - Confusing
astro servewith build command - Trying
astro runwhich doesn't exist
astro dev astro build astro dev
What will happen when you run the last
astro dev command?Solution
Step 1: Understand
Each time you runastro devbehaviorastro dev, it starts a fresh development server with live reload, independent of previous builds.Step 2: Recognize build does not block dev
Runningastro buildcreates production files but does not prevent runningastro devagain later.Final Answer:
It will start the dev server showing live updates again -> Option BQuick Check:
Dev server always starts fresh onastro dev[OK]
- Thinking build locks out dev server
- Assuming dev overwrites build files
- Expecting errors after build when running dev
astro build but the output folder is empty. What is the most likely cause?Solution
Step 1: Check build requirements
astro buildrequires valid Astro files; syntax errors prevent successful build output.Step 2: Eliminate other causes
astro devis not required before build; build works locally before publishing; missingpackage.jsonusually causes install errors, not empty build.Final Answer:
There is a syntax error in your Astro files stopping the build -> Option DQuick Check:
Syntax errors block build output [OK]
- Thinking dev must run before build
- Assuming build only works after publishing
- Ignoring syntax errors in source files
Solution
Step 1: Identify optimization techniques
Enabling image optimization and removing unused CSS during build reduces file size and improves load speed.Step 2: Understand deployment best practices
Deploying dev server files or source files directly is inefficient and not recommended; default build may not optimize assets fully.Final Answer:
Runastro buildwith image optimization enabled and remove unused CSS -> Option AQuick Check:
Optimize images + CSS during build = faster site [OK]
- Deploying dev server files instead of build output
- Skipping build and uploading source files
- Not enabling optimizations in build config
Ready to prove it?
Pass the test and this pattern moves unknown
