Development Setup
This guide covers the development workflow for the Sistema Venta frontend application, including running the dev server, testing, and building the application.Installation
Install Dependencies
Navigate to the frontend directory and install all npm packages:This will install all dependencies from
package.json, including:- Angular 14.2.0 framework
- Angular Material 14.2.7
- Chart.js for visualizations
- SweetAlert2 for notifications
- XLSX for Excel exports
- Moment.js for date handling
Configure API Endpoint
Update the backend API endpoint in your environment file:
src/environments/environment.ts
Ensure your backend API is running and accessible at the configured endpoint.
Development Server
Starting the Server
Run the development server with hot reload:http://localhost:4200/ by default.
The dev server automatically recompiles and reloads when you make changes to source files.
Development Configuration
The development build uses these optimizations (configured inangular.json):
angular.json
Application Structure
Feature Modules
The application uses lazy loading for better performance:Component Organization
- Pages
- Services
Main application pages under
/pages route:- Dashboard (
/pages/dashboard) - Analytics and metrics - Usuarios (
/pages/usuarios) - User management - Productos (
/pages/productos) - Product catalog - Venta (
/pages/venta) - New sales transaction - Historial Venta (
/pages/historial_venta) - Sales history - Reportes (
/pages/reportes) - Reports and analytics
Working with Services
Creating a New Service
Generate a new service using Angular CLI:Service Pattern
All services follow this pattern:Building the Application
Development Build
Build with source maps and no optimization:Watch Mode
Continuously build on file changes:Production Build
Optimized build for production:- Minification and optimization
- AOT (Ahead-of-Time) compilation
- Tree shaking to remove unused code
- Output hashing for cache busting
- Environment file replacement
Production builds are output to
dist/app-sistema-venta/Build Configuration
Bundle Size Budgets
The application has bundle size limits configured:angular.json
If your build exceeds these limits, you’ll receive warnings or errors. Consider code splitting or lazy loading.
Testing
Running Unit Tests
Execute unit tests via Karma:Test Configuration
Tests are configured inkarma.conf.js with:
- Jasmine test framework
- Chrome launcher
- Code coverage reporting
Common Development Tasks
Debugging
Browser DevTools
The development build includes source maps for debugging:- Open Chrome DevTools (F12)
- Navigate to Sources tab
- Find your TypeScript files under
webpack:// - Set breakpoints and debug
Angular DevTools
Install the Angular DevTools browser extension for:- Component tree inspection
- Change detection profiling
- Dependency injection debugging
Common Issues
CORS Errors
CORS Errors
If you encounter CORS errors when calling the API:
- Ensure the backend API has CORS configured
- Check the API endpoint in
environment.ts - Consider using a proxy configuration (create
proxy.conf.json)
Module Not Found Errors
Module Not Found Errors
If you see module import errors:
Port Already in Use
Port Already in Use
If port 4200 is already in use:
Next Steps
Configuration
Review configuration options and service setup
Deployment
Deploy your application to production