Deploying to Netlify lets you put your Astro website online so anyone can visit it. It makes sharing your work easy and fast.
Deploying to Netlify in Astro
1. Push your Astro project to a GitHub, GitLab, or Bitbucket repository. 2. Go to https://netlify.com and sign up or log in. 3. Click 'New site from Git'. 4. Connect your Git provider and select your Astro project repository. 5. Set the build command to: npm run build 6. Set the publish directory to: dist 7. Click 'Deploy site' and wait for Netlify to build and publish your site.
The npm run build command runs Astro's build process to create static files.
The dist folder is where Astro puts the final website files to serve.
Build command: npm run build Publish directory: dist
If using Yarn: Build command: yarn build Publish directory: dist
If you want to deploy a specific branch: Select the branch in Netlify's deploy settings before deploying.
This step-by-step shows how to prepare your Astro project and deploy it to Netlify for free hosting.
1. Create a new Astro project: npm create astro@latest 2. Initialize git and push to GitHub: git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/your-astro-site.git git push -u origin main 3. On Netlify: - Click 'New site from Git' - Connect GitHub and select your repo - Set build command: npm run build - Set publish directory: dist - Deploy site 4. Wait for build to finish and visit your site URL.
Make sure your package.json has a build script like "build": "astro build".
Netlify automatically detects changes in your Git repo and redeploys your site.
You can add a custom domain in Netlify settings after deployment.
Deploying to Netlify makes your Astro site live on the internet quickly.
Connect your Git repo, set build and publish settings, and Netlify handles the rest.
You get free hosting with easy updates and custom domain support.
Practice
Solution
Step 1: Understand deployment meaning
Deployment means making a website available online for others to visit.Step 2: Identify Netlify's role
Netlify hosts your Astro site so it can be accessed on the internet anytime.Final Answer:
To make the site live and accessible on the internet -> Option AQuick Check:
Deploying = Making site live [OK]
- Thinking Netlify edits code directly
- Confusing deployment with app conversion
- Assuming deployment is just local backup
Solution
Step 1: Identify Netlify configuration file
Netlify usesnetlify.tomlto set build commands and publish directories.Step 2: Differentiate from other files
package.jsonmanages dependencies,astro.config.mjsconfigures Astro, andindex.htmlis a page file.Final Answer:
netlify.toml -> Option BQuick Check:
Build commands set in netlify.toml [OK]
- Confusing package.json with Netlify config
- Thinking astro.config.mjs controls deployment
- Using index.html for build commands
netlify.toml snippet:[build] command = "npm run build" publish = "dist"
What happens when you push your Astro site to Netlify?
Solution
Step 1: Understand build command in netlify.toml
The commandnpm run buildtells Netlify how to build the site before publishing.Step 2: Understand publish directory
Thepublishfolderdistis where the built site files are located for Netlify to serve.Final Answer:
Netlify runs npm run build and publishes the dist folder -> Option DQuick Check:
Build command + publish folder = deploy site [OK]
- Assuming Netlify uses npm start by default
- Thinking Netlify publishes source files directly
- Believing dist folder is invalid
Solution
Step 1: Check publish directory setting
If thepublishfolder is wrong, Netlify serves an empty or wrong folder causing 404 errors.Step 2: Verify other options
Code pushed to GitHub is needed but usually causes build errors, not 404. Netlify supports Astro. Theindex.htmlis inside the publish folder, not root.Final Answer:
The publish directory in netlify.toml is set incorrectly -> Option AQuick Check:
Wrong publish folder = 404 error [OK]
- Blaming Netlify for no Astro support
- Assuming missing index.html in root causes 404
- Ignoring publish directory misconfiguration
Solution
Step 1: Connect Git repo to Netlify
Linking your GitHub repo allows Netlify to pull code and build automatically on pushes.Step 2: Configure build and publish settings
Set the build command (e.g.,npm run build) and publish folder (e.g.,dist) in Netlify.Step 3: Add custom domain in Netlify
Use Netlify's domain settings to add your own domain for the site URL.Final Answer:
Connect your Git repo to Netlify, set build command and publish folder, then add your custom domain in Netlify settings -> Option CQuick Check:
Git + build + domain = full Netlify deploy [OK]
- Uploading files manually instead of Git integration
- Thinking Netlify needs manual deploy requests
- Trying to create Astro projects inside Netlify dashboard
Ready to prove it?
Pass the test and this pattern moves unknown
