Skip to main content

Overview

This guide covers deploying the Sistema Venta Angular application to various production environments, including static hosting, web servers, and cloud platforms.

Pre-Deployment Checklist

1

Update Production Environment

Configure your production API endpoint in src/environments/environment.prod.ts:
src/environments/environment.prod.ts
export const environment = {
  production: true,
  endpoint: "https://your-api-domain.com/api/"
};
Ensure the endpoint URL ends with a trailing slash and uses HTTPS in production.
2

Review Build Budgets

Check that your bundle sizes are within limits:
angular.json
"budgets": [
  {
    "type": "initial",
    "maximumWarning": "500kb",
    "maximumError": "1mb"
  }
]
Run a test build to verify:
ng build --configuration production
3

Test Production Build Locally

Install a static server and test the production build:
npm install -g http-server
ng build --configuration production
cd dist/app-sistema-venta
http-server -p 8080
Visit http://localhost:8080 to verify everything works.
4

Verify API Connectivity

Ensure your production API is:
  • Accessible from the deployment environment
  • Configured with CORS for your frontend domain
  • Using HTTPS (required for production)

Production Build

Build Command

Create an optimized production build:
npm run build

Build Output

The production build generates optimized files in dist/app-sistema-venta/:
dist/app-sistema-venta/
├── index.html              # Entry point
├── main.[hash].js          # Application code
├── polyfills.[hash].js     # Browser polyfills
├── runtime.[hash].js       # Webpack runtime
├── styles.[hash].css       # Compiled styles
├── assets/                 # Static assets
├── favicon.ico
└── 3rdpartylicenses.txt    # Third-party licenses
File names include content hashes for cache busting. The hash changes when file contents change.

Build Optimizations

Production builds include:
  • AOT Compilation: Ahead-of-Time compilation for faster rendering
  • Minification: Compressed JavaScript and CSS
  • Tree Shaking: Removes unused code
  • Dead Code Elimination: Removes unreachable code
  • Bundle Optimization: Optimized chunk splitting
  • Output Hashing: Cache busting with content hashes

Deployment Options

Option 1: IIS (Internet Information Services)

1

Build the Application

ng build --configuration production
2

Configure web.config

Create a web.config file in dist/app-sistema-venta/ for URL rewriting:
dist/app-sistema-venta/web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
  </system.webServer>
</configuration>
3

Deploy to IIS

  1. Open IIS Manager
  2. Create a new website or application
  3. Set physical path to dist/app-sistema-venta/
  4. Configure application pool (use .NET CLR version: No Managed Code)
  5. Set permissions for IIS_IUSRS
  6. Start the website

Option 2: Apache Web Server

1

Build the Application

ng build --configuration production
2

Create .htaccess

Create a .htaccess file in dist/app-sistema-venta/:
dist/app-sistema-venta/.htaccess
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
3

Deploy to Apache

# Copy files to web root
sudo cp -r dist/app-sistema-venta/* /var/www/html/

# Set permissions
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

# Ensure mod_rewrite is enabled
sudo a2enmod rewrite
sudo systemctl restart apache2

Option 3: Nginx

1

Build the Application

ng build --configuration production
2

Configure Nginx

Create an Nginx configuration:
/etc/nginx/sites-available/sistema-venta
server {
    listen 80;
    server_name your-domain.com;
    root /var/www/sistema-venta;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    # Cache static assets
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;

    # Gzip compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json;
}
3

Deploy to Nginx

# Copy files
sudo mkdir -p /var/www/sistema-venta
sudo cp -r dist/app-sistema-venta/* /var/www/sistema-venta/

# Enable site
sudo ln -s /etc/nginx/sites-available/sistema-venta /etc/nginx/sites-enabled/

# Test and reload
sudo nginx -t
sudo systemctl reload nginx

Option 4: Cloud Platforms

1

Create netlify.toml

netlify.toml
[build]
  command = "npm run build"
  publish = "dist/app-sistema-venta"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200
2

Deploy

# Install Netlify CLI
npm install -g netlify-cli

# Build and deploy
ng build --configuration production
netlify deploy --prod --dir=dist/app-sistema-venta

Docker Deployment

Create Dockerfile

# Stage 1: Build
FROM node:14-alpine AS build

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .
RUN npm run build -- --configuration production

# Stage 2: Serve with Nginx
FROM nginx:alpine

COPY --from=build /app/dist/app-sistema-venta /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

Build and Run Docker Container

# Build image
docker build -t sistema-venta-frontend .

# Run container
docker run -d -p 80:80 --name sistema-venta sistema-venta-frontend

# View logs
docker logs sistema-venta

Docker Compose

docker-compose.yml
version: '3.8'

services:
  frontend:
    build: .
    ports:
      - "80:80"
    restart: unless-stopped
    environment:
      - NODE_ENV=production

SSL/HTTPS Configuration

Always use HTTPS in production for security. The Material Design API and modern browsers require HTTPS for many features.

Using Let’s Encrypt with Certbot

1

Install Certbot

sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
2

Obtain Certificate

sudo certbot --nginx -d your-domain.com -d www.your-domain.com
3

Auto-renewal

Certbot automatically adds a renewal cron job. Test it:
sudo certbot renew --dry-run

Performance Optimization

Enable Compression

Ensure your web server serves compressed files:
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
  text/plain
  text/css
  text/xml
  text/javascript
  application/json
  application/javascript
  application/xml+rss
  application/atom+xml
  image/svg+xml;

Cache Headers

Set appropriate cache headers:
# Immutable files (with hashes)
location ~* \.[0-9a-f]{20}\.(js|css)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

# index.html - never cache
location = /index.html {
    add_header Cache-Control "no-cache, no-store, must-revalidate";
}

# Other static assets
location ~* \.(jpg|jpeg|png|gif|ico|svg|woff|woff2)$ {
    expires 6M;
    add_header Cache-Control "public";
}

Monitoring and Troubleshooting

Health Check Endpoint

The index.html serves as a basic health check:
curl -I https://your-domain.com/
# Should return: HTTP/1.1 200 OK

Common Issues

Problem: Direct navigation to routes returns 404.Solution: Configure server URL rewriting to always serve index.html for non-file requests. See deployment-specific configurations above.
Problem: API calls fail with CORS errors in production.Solution: Configure your backend API to allow requests from your frontend domain:
Program.cs (Backend)
builder.Services.AddCors(options => {
    options.AddPolicy("AllowFrontend", policy => {
        policy.WithOrigins("https://your-domain.com")
              .AllowAnyMethod()
              .AllowAnyHeader();
    });
});
Problem: Production environment settings not applied.Solution: Ensure you’re building with --configuration production and verify file replacement in angular.json.
Problem: Build exceeds bundle size budgets.Solutions:
  • Enable lazy loading for feature modules
  • Analyze bundle with: ng build --configuration production --stats-json
  • Use webpack-bundle-analyzer: npx webpack-bundle-analyzer dist/app-sistema-venta/stats.json
  • Remove unused dependencies

Logging and Analytics

Consider adding:
  • Application Insights (Azure) or CloudWatch (AWS) for monitoring
  • Sentry or similar for error tracking
  • Google Analytics for user analytics
app.component.ts
// Example: Add error tracking
import * as Sentry from '@sentry/angular';

Sentry.init({
  dsn: 'your-sentry-dsn',
  environment: environment.production ? 'production' : 'development'
});

Continuous Deployment

GitHub Actions Example

.github/workflows/deploy.yml
name: Deploy Frontend

on:
  push:
    branches: [ main ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'
        cache: 'npm'
    
    - name: Install dependencies
      run: npm ci
      working-directory: ./AppSistemaVenta
    
    - name: Build
      run: npm run build
      working-directory: ./AppSistemaVenta
    
    - name: Deploy to S3
      uses: jakejarvis/s3-sync-action@master
      with:
        args: --delete
      env:
        AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        SOURCE_DIR: './AppSistemaVenta/dist/app-sistema-venta'

Post-Deployment Verification

1

Verify Application Loads

  • Navigate to your production URL
  • Check that the login page displays correctly
  • Verify all assets load (check browser console)
2

Test Core Functionality

  • Login with test credentials
  • Navigate to each main page
  • Test API connectivity
  • Verify data displays correctly
3

Check Performance

  • Run Lighthouse audit in Chrome DevTools
  • Verify load times are acceptable
  • Check bundle sizes in Network tab
4

Monitor Logs

  • Check server access logs
  • Monitor application errors
  • Verify API calls are successful

Next Steps

Configuration

Review configuration options and customize settings

Development

Return to development guide for updates and enhancements

Build docs developers (and LLMs) love