Skip to main content

Building for Production

This guide covers building VozCraft for production deployment. Vite provides highly optimized builds with automatic code splitting, minification, and asset optimization.

Quick Start

Build VozCraft for production with a single command:
This creates an optimized production build in the dist/ directory, ready for deployment.
Build time: Typically 5-15 seconds on modern hardware.Output size: ~150-200 KB (gzipped) for the complete application.

Build Process

The build Script

The build command is defined in package.json:
package.json
This executes Vite’s production build process.

Build Configuration

Vite uses vite.config.js for build settings:
vite.config.js
This is the minimal configuration. VozCraft uses Vite’s intelligent defaults for optimal production builds.

What Happens During Build

1

Dependency resolution

Vite analyzes all imports and dependencies:
All dependencies are traced and bundled.
2

JSX transformation

React JSX is compiled to JavaScript:
3

Code minification

JavaScript is minified using esbuild:
Minification savings: Typically 40-60% size reduction.
4

Asset optimization

Images and other assets are optimized:
  • Images: Compressed and copied to dist/assets/
  • Fonts: Inlined or copied based on size
  • SVG: Minified and optimized
5

CSS processing

Inline styles are extracted and optimized:
VozCraft uses inline styles exclusively, so no separate CSS file is generated.
6

Code splitting

Vite automatically splits code for optimal loading:
  • Vendor chunks: React and React-DOM in separate chunks
  • Dynamic imports: Lazy-loaded components (if any)
  • Entry point: Main application code
Example output:
7

Hash generation

Asset filenames include content hashes for cache busting:
Cache busting: Hash changes when content changes, forcing browser cache refresh.

Build Output

Directory Structure

After building, the dist/ directory contains:

File Sizes

Typical production build sizes:
Gzip compression is typically applied by web servers (Nginx, Apache, CDNs) automatically. The gzipped size is what users actually download.

Optimized index.html

The built index.html includes minified content and hashed asset references:
dist/index.html
  1. Module script: Points to hashed bundle
  2. Crossorigin: Enables CORS for module loading
  3. Inline styles removed: Extracted to JS bundle
  4. Whitespace minified: Reduced HTML size

Advanced Build Configuration

Custom Vite Configuration

You can extend vite.config.js for custom build behavior:
vite.config.js
Enable source maps for production debugging:
Options:
  • true: Separate .map files
  • 'inline': Inline source maps (larger bundle)
  • 'hidden': Source maps without reference (for error tracking)
  • false: No source maps (smallest bundle)
Source maps expose your source code. Only enable in production if you need debugging or error tracking.

Environment-Specific Builds

Create different builds for different environments:
vite.config.js
Build with specific mode:

Build Optimization Strategies

1. Code Splitting

Split large components into separate chunks:
src/App.jsx
When to use code splitting:
  • Large third-party libraries
  • Route-based components (if using React Router)
  • Features used by < 50% of users
  • Heavy visualization components

2. Tree Shaking

Vite automatically removes unused code:
Tree shaking requirements:
  • Use ES modules (import/export)
  • Avoid CommonJS (require)
  • Use named imports when possible

3. Asset Optimization

Image Optimization

vite.config.js
Requires installing: npm install -D vite-plugin-imagemin

Font Loading

VozCraft loads Google Fonts. Consider self-hosting for better performance:

4. Bundle Analysis

Analyze bundle size to identify optimization opportunities:
vite.config.js
After building, opens a treemap visualization showing bundle composition.

Build Scripts

Custom Build Scripts

Add specialized build scripts to package.json:
package.json
Remove old build before creating new one:
Ensures no stale files remain in dist/.

Performance Budgets

Set performance budgets to catch bundle bloat:
vite.config.js
If a chunk exceeds the limit, Vite shows a warning:
Consider code splitting to reduce chunk sizes.

Testing the Build

Local Preview

Test the production build locally:
This serves the dist/ directory at http://localhost:4173.
Preview server features:
  • Simulates production environment
  • Serves compressed files
  • Uses production URLs
  • Tests PWA functionality

Serve with Different Servers

Visit http://localhost:8000

Build Checklist

1

Clean build

Start with a clean slate.
2

Check build output

Verify:
  • No build errors or warnings
  • Bundle sizes are reasonable
  • All assets copied to dist/
3

Test locally

Test all functionality:
  • Speech synthesis works
  • Audio download works
  • History persists
  • PWA manifest loads
  • Dark/light theme works
4

Check console

Open DevTools and verify:
  • No JavaScript errors
  • No 404s for missing assets
  • No CSP violations
5

Test on mobile

  • Open preview URL on phone
  • Test PWA installation
  • Verify responsive design
  • Test touch interactions
6

Lighthouse audit

Run Lighthouse in Chrome DevTools:
  • Performance: 90+
  • Accessibility: 90+
  • Best Practices: 90+
  • SEO: 90+
  • PWA: Installable

Common Build Issues

Cause: Using features not supported by target browsers.Solution:
vite.config.js
Or add polyfills for older browsers.
Cause: Incorrect asset paths or base URL.Solution:
vite.config.js
Use root-relative paths:
Causes:
  • Large dependencies
  • Unused code not tree-shaken
  • Unoptimized images
Solutions:
  1. Analyze bundle:
  1. Lazy load heavy components:
  1. Replace large dependencies with smaller alternatives
  2. Enable compression on server (gzip/brotli)
Solution:
Or in package.json:

Continuous Integration

GitHub Actions

.github/workflows/build.yml

Next Steps

Deployment

Deploy your build to production

PWA Setup

Optimize PWA configuration