Reputation: 8605
I love Angular CLI and use it for all my Angular projects. But every now and again I run into a use case that the tremendously bad official docs don't help with. So at the risk of bundling too much into one question, here are my most pressing questions:
UglifyJS
.ng build --app
"Specifies app name or index to use." That little sentence there is the sum total of all documentation. I have a case where it would be handy to have one index.html
for one environment and another index.html
for another. I thought this may be it, but it seems not. Does anyone know how to use this, or to conditionally supply a different index.html
?dev
and prod
act as always, but devextra
and prodextra
deploys an extra file (a bit like conditionally adding something to scripts
in .angular-cli.json
.Points 2 & 3 are for integration with another tool. My present workaround is a manual edit of index.html.
Upvotes: 2
Views: 1630
Reputation: 8605
I have found a good answer for items 2 & 3. Number one is still a mystery.
Here is an example .angular-cli.json
showing how to do it:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "project-name"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [
"somescript.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}, {
"root": "src",
"outDir": "../completely/different/folder",
"assets": [
"assets",
"favicon.ico"
],
"index": "otherindex.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [
"somescript.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.extra.dev.ts",
"prod": "environments/environment.extra.prod.ts"
}
}
],
/* These are empty for brevity */
"e2e": {},
"lint": [],
"test": {},
"defaults": {}
}
So this is a little big and most of it is duplicated, so allow me to give you a tour.
apps
array actually has two objects in it. Normally there is only one and I'm not sure when multiple app support was added, but that is what the --app
command line is for. So ng build --app 0
uses the first object for configuration and ng build --app 1
uses the second one. The same with ng serve
.environment
files. Also, notice the two configurations deploy two different (and totally believable) script files. There is actually so much you can vary here, it's impressive.A few gotchas:
environmentSource
. It then seems to just default to the dev
environment from the first configuration.deployUrl
only works on the command line and baseUrl
can't be specified in config at all. There may be others.root
I really can't see why you wouldn't just do a completely different app. It probably isn't wise to stretch this past its design envelope.My current thinking is that I'll use a single .angular-cli.json
with multiple configurations and then create batch files to wrap my ng build
/serve
calls.
Upvotes: 1