Adjusting various angular-cli configuration files or providing input variables

My application caters to different customers, requiring personalized configurations based on their needs.
I am looking for a way to customize the settings in the angular-cli.json file each time I run ng build. Is there a method to:

1) Dynamically change the angular-cli.json file during build?
2) Pass a variable to modify the 'styles' and 'dist' fields?

Currently, I have to manually update the configuration for each client before building the app. I aim to automate this process by creating a script that can handle multiple builds consecutively, but customization seems impossible without being able to personalize angular-cli.json for each build.

UPDATE

I came across this link, but I'm unsure how to implement it. I checked the documentation here with no luck. Should I add a property under the app array in angular-cli.json? Or do I need to create another array similar to the one for apps?

UPDATE 2

This is what my configuration looks like under apps:

{
  "name":"app1",
  "root": "src",
  "outDir": "dist",
  "assets": [
    "fonts",
    "images",
    "assets",
    "favicon.ico"
  ],
  "index": "index.html",
  "main": "main.ts",
  "test": "test.ts",
  "tsconfig": "tsconfig.json",
  "prefix": "app",
  "mobile": false,
  "styles": [
    "paper.css",
    "styles.css",
    "style_app1.css"
  ],
  "scripts": ["../node_modules/chart.js/dist/Chart.bundle.min.js"],
  "environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
},
{
  "name":"app2",
  "root": "src",
  "outDir": "dist2",
  "assets": [
    "fonts",
    "images",
    "assets",
    "favicon.ico"
  ],
  "index": "index.html",
  "main": "main.ts",
  "test": "test.ts",
  "tsconfig": "tsconfig.json",
  "prefix": "app",
  "mobile": false,
  "styles": [
    "paper.css",
    "styles.css",
    "style_app2.css"
  ],
  "scripts": ["../node_modules/chart.js/dist/Chart.bundle.min.js"],
  "environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
}

It appears that when I run ng build --app app2, nothing gets generated in dist2. This approach does not seem to work as expected.

Answer №1

In the file .angular-cli.json, there is a property called apps that allows for multiple app entries within an array. By default, ng creates a single entry as shown below:

{
  "root": "src",
  "outDir": "dist",
  "assets": [
    "assets",
    "favicon.ico"
  ],
  "index": "index.html",
  "main": "main1.ts",
  "polyfills": "polyfills.ts",
  "test": "test.ts",
  "tsconfig": "tsconfig.app.json",
  "testTsconfig": "tsconfig.spec.json",
  "prefix": "app",
  "styles": [
    "styles.css"],
  "scripts": [],
  "environmentSource": "environments/environment.ts",
  "environments": {
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
},

The example above outlines an app with main1.ts housing the bootstrap code. If another app in the same project requires main2.ts for bootstrap code, you must duplicate the configuration but change "main" to "main2.ts". This will result in an array of two apps, allowing you to specify which one to build using the corresponding index, like so:

ng build --app 0

or

ng build --app 1

To further identify each app configuration, you can add a "name" property:

"apps": [
    { "name":"app1",
      "root": "src",
      "outDir": "dist",
       ... 

You can then trigger the build with the specific app name like this:

ng build --app app1

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

simulate express-jwt middleware functions for secure routes

I am currently facing an issue with my code snippet, which looks like this: import app from '../src/app'; beforeAll(() => jest.mock('../src/middleware/auth', () => (req: Request, res: Response, next: NextFunction) => { ...

Resolving the Error: "Type 'Customer | undefined' is not compatible with type 'Customer'" in Angular

I encountered an issue with the following code: ... export class ListCustomersComponent implements OnInit { customers: Array<Customer> = []; showCustomer?: Customer; isSelected: boolean = false; deletedCustomer?: Customer; returnedMessa ...

The error message "Webpack is not applying the style from leaflet.css"

Currently utilizing the ngX-Rocket angular 8 starter, I am looking to integrate the leaflet map library into my project from this source: https://github.com/Asymmetrik/ngx-leaflet After including the file in my index.html document, I encountered the follo ...

Upgrade from AngularJS to Angular 5 in Eclipse

Currently, I have a web application built in AngularJS, but I am looking to transition it to Angular 5. The existing webapp is running on Eclipse with a Tomcat server and has Java as the backend language. I have created a new version of the web applicati ...

What is the process for defining a property type as a textual representation of a Type name in TypeScript?

Consider the following classes and interface: class Foo {} interface Bar {} I am looking to define a type that includes a property with a specified type: type DynamicPropertyName<T> = ... <-- ??? After defining the type, I want to use it like th ...

What might be the reason why the custom markers on the HERE map are not displaying in Angular?

I'm having trouble displaying custom icons on HERE maps. Despite not receiving any errors, the icons are not showing up as expected. I have created a demo at the following link for reference: https://stackblitz.com/edit/angular-ivy-zp8fy5?file=src%2Fa ...

Row buttons in a mat-table that can be clicked individually

In my mat-table, each row represents an audio recording for a call. At the end of each row, there is a play button that plays the respective audio file when clicked. However, whenever I click any play button, the correct audio file plays but all the play b ...

When incorporating HTML5 Canvas fonts into a PDF using jspdf, the text may appear blurry

I have developed a function that scales down the font size until the text width is smaller than the canvas width. This text is then added to a canvas containing a QR code. Subsequently, this canvas is included in a PDF file. The issue I am encountering i ...

Parsing of the module failed due to an unexpected character appearing when trying to insert a TTF file into the stylesheet

As a newcomer to Angular, I recently completed the tutorial and am now working on my first app. While trying to add an OTF file, everything went smoothly. However, when I made a change to my app.component.css file and included this code snippet: @font-fa ...

The options passed to createReadStream in TypeScript do not accept {start: 90, end: 99}

After updating to TypeScript 1.6.2, I encountered an issue with my call to createReadStream(). The problem arises because the type definition in node.d.ts does not recognize 'start' and 'end' in the options parameter. var st = fs.crea ...

Can you explain how the "reduce" function can be implemented using an interface in TypeScript?

Can you explain the "reduce" function using an interface in TypeScript? https://i.stack.imgur.com/X1VxL.png ...

Modify the selected toggle buttons' color by utilizing the MUI ThemeProvider

I am currently working on customizing the color of selected toggle buttons within my React app using TypeScript and ThemeProvider from @mui/material 5.11.13. Despite my efforts, when a toggle button is selected, it still retains the default color #1976d2, ...

Error encountered in Angular CLI: Attempting to access property 'value' of an undefined variable

I am encountering an issue while trying to retrieve the values of radio buttons and store them in a MySql database. The error message I receive is TypeError: Cannot read property 'value' of undefined. This project involves the use of Angular and ...

Extracting information from an Observable in Angular: A comprehensive guide

I am currently working on an Angular application that interacts with a server through RESTful requests, and receives a JSON stream response containing objects of a specific type. The interface for these objects is as follows: export interface Personal { ...

Why is it that I am able to invoke my Redux action creators from the componentWillMount() method, but not from my event handler function?

I'm currently developing an application using React, Redux, and TypeScript. My Redux store is all set up with initial state and it's working fine in populating my components. Now, I am in the process of connecting a form that will trigger my act ...

The issue with importing fonts in CSS causing an error is encountered when utilizing an exported Angular library

I have a components library for Angular that relies on line-awesome icons. To include the necessary fonts and styles, I am using a CDN in the main SCSS file as shown below: @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400; ...

I'm looking to switch out the `~` to turn it into a URL for the backend, seeing as `<img alt="" src="~/media/Banner/plane.JPG">` is returning a 404 error

1. Received an HTTP Request and JSON response from the backend localhost:3000 (entered value using wysiwyg) { "Description": "&lt;img alt=&quot;&quot; src=&quot;~/media/Banner/plane.JPG&quot; /&gt;1 test berita&lt ...

Incorporate a generic type into a React Functional Component

I have developed the following component: import { FC } from "react"; export interface Option<T> { value: T; label: string; } interface TestComponentProps { name: string; options: Option<string>[]; value: string; onChang ...

Access route information external to the router outlet

Can we access the data parameters in a component that is located outside of a router outlet? const appRoutes: Routes = [ { path: '', component: SitesComponent }, { path: 'pollutants/newpollutant', component: PollutantComponent, data: { ...

Embed the value of an array in HTML

Upon running console.log, the data output appears as follows: {TotalPendingResponseCount: 0, TotalRequestSendCount: 1, TotalRequestReceivedCount: 1, TotalRequestRejectCount: 3} To store this information, I am holding it in an array: userData : arrayResp ...