Build & Deployment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
The Marketplace project consists of a NestJS backend and an Angular frontend. The build and deployment configuration defines how these separate applications are compiled, optimized, and prepared for various environments. This configuration relies on the Angular CLI for the frontend and the Nest CLI for the backend, utilizing environment-specific variables and build scripts to manage the lifecycle of each service.
Backend Configuration (NestJS)
The backend uses the NestJS framework and resides in the marketplace-backend/app directory. The build process transforms TypeScript source code into executable JavaScript within a dist folder.
Lifecycle Scripts
The backend lifecycle is managed via NPM scripts defined in package.json.
| Script | Command | Purpose |
|---|---|---|
prebuild | rimraf dist | Deletes the existing build directory to ensure a clean state. |
build | nest build | Compiles the TypeScript code using the Nest CLI. |
start | nest start | Starts the application using the default configuration. |
start:dev | env-cmd -f local.env nest start --watch | Runs the app in watch mode with local environment variables. |
start:prod | env-cmd -f production.env node dist/main | Runs the compiled application using production environment variables. |
Sources: marketplace-backend/app/package.json:9-15
Runtime Initialization
The backend entry point is main.ts, which initializes the NestJS application and configures global middleware. It retrieves the server port from the PORT environment variable and sets up Swagger documentation using the route specified in SWAGGER_DOCS_ROUTE.
Frontend Configuration (Angular)
The frontend application is managed through angular.json, which defines the workspace projects and their respective build targets.
Build Architect
The build architect uses the @angular-devkit/build-angular:browser builder. It defines specific paths for the entry file, polyfills, and assets.
- Output Path:
dist/marketplace-frontend - Main Entry:
src/main.ts - Polyfills:
src/polyfills.ts - Styles:
src/styles.less
Sources: marketplace-frontend/angular.json:13-33
Build Environments and File Replacements
For production builds, the configuration replaces the default environment file with a production-specific version. This allows the application to point to different backend endpoints without changing the source code.
| Source File | Replacement File | Configuration |
|---|---|---|
src/environments/environment.ts | src/environments/environment.prod.ts | production |
Sources: marketplace-frontend/angular.json:42-47
Optimization and Performance
Production configurations enable several optimizations to improve load times and security:
- Optimization: Set to
trueto enable minification and dead code elimination. - Build Optimizer: Set to
trueto further reduce bundle size. - Output Hashing: Set to
allto prevent browser caching of old versions. - Budgets: Defines limits for bundle sizes. For example, the initial bundle has a warning limit of 2mb and an error limit of 5mb.
Sources: marketplace-frontend/angular.json:48-64
Environment Settings
Both applications rely on externalized configurations to adapt to different environments.
Frontend Environment
The default frontend environment configuration defines the connection to the backend and supported languages.
production: Boolean flag for production mode.backendServerEndpoint: The URL of the API (e.g.,http://as.localhost.com:4000).defaultLocale: The default language (e.g.,en).
Sources: marketplace-frontend/src/environments/environment.ts:7-12
Dependency Management
The project uses package.json to manage both runtime and development dependencies.
Summary
The build and deployment system is structured to separate concerns between the NestJS backend and the Angular frontend. By utilizing the Nest CLI and Angular CLI, the project ensures consistent build artifacts. Environment-specific configurations and file replacements allow the system to move from development to production seamlessly while maintaining performance through bundle optimization and budget constraints.