Production Build
Building the Application
To create an optimized production build, run:- Bundle and minify your JavaScript and CSS
- Optimize assets and images
- Generate production-ready files in the
dist/directory - Tree-shake unused code for smaller bundle sizes
Build Output
After running the build command, you’ll find the compiled files in thedist/ directory:
Vite automatically adds content hashes to filenames for optimal browser caching.
Preview Production Build Locally
Before deploying, you can preview the production build locally:dist/ at http://localhost:4173.
The preview server is meant for previewing the build locally and should not be used as a production server.
Deployment to Netlify
The Pokedex application is deployed to Netlify. You can view the live application at: Live URL: https://pokedex-eliasmari.netlify.appDeployment Options
Option 1: Deploy via Git (Recommended)
Connect your Git repository to Netlify for automatic deployments:
- Push your code to GitHub, GitLab, or Bitbucket
- Log in to Netlify
- Click “Add new site” → “Import an existing project”
- Select your Git provider and repository
- Configure build settings:
- Build command:
npm run build - Publish directory:
dist
- Build command:
- Click “Deploy site”
Option 2: Deploy via Netlify CLI
Deploy directly from your terminal:Follow the prompts to link your site or create a new one.
Option 3: Manual Deploy
Deploy by dragging and dropping:
- Build your application:
npm run build - Go to Netlify Drop
- Drag the
dist/folder to the upload area
Netlify Configuration
For optimal deployment, create anetlify.toml file in your project root:
Why Redirects Matter
Vue Router uses HTML5 history mode, which means:- URLs look clean (e.g.,
/pokemons/pikachuinstead of/#/pokemons/pikachu) - Direct navigation to routes requires server-side configuration
- The redirect rule ensures all routes are handled by
index.html
Environment Variables
If your application uses environment variables:Environment variables in Vite must be prefixed with
VITE_ to be exposed to your client-side code.Setting Environment Variables in Netlify
- Go to your site in Netlify
- Navigate to “Site configuration” → “Environment variables”
- Add your variables with the
VITE_prefix
Build Optimizations
Vite Build Features
Vite provides several optimizations out of the box:- Code Splitting: Automatic chunking for better caching
- Tree Shaking: Removes unused code
- Minification: Reduces file sizes
- Asset Optimization: Compresses images and assets
- CSS Code Splitting: Separates CSS for each component
Manual Optimization Tips
Performance Checklist
Before deploying to production:- Run
npm run buildwithout errors - Test the production build with
npm run preview - Verify all routes work correctly
- Check that API calls are using production endpoints
- Test on multiple browsers and devices
- Verify images and assets load correctly
- Check console for any errors or warnings
Deployment Best Practices
Use Git-based Deployments
Connect your Git repository to Netlify for automatic deployments on every push to the main branch.
Enable Deploy Previews
Netlify automatically creates preview deployments for pull requests, allowing you to test changes before merging.
Continuous Deployment
With Git-based deployment, your workflow becomes:- Detect the push
- Run
npm run build - Deploy the
dist/folder - Update your live site
Troubleshooting Deployment
Common Build Errors
404 Errors on Routes
If you get 404 errors when navigating directly to routes:- Verify your
netlify.tomlredirect rule is in place - Check that the redirect rule uses status
200(not301or302)
Cache Issues
If changes don’t appear after deployment:- Clear your browser cache
- Use Netlify’s “Clear cache and deploy site” option
- Check that asset hashes are updating in filenames
Next Steps
- Learn about PokeAPI Integration to understand data fetching
- Review Development Setup for local development
- Explore Netlify’s documentation for advanced features