ng serve 和 ng build 的 cli 配置中的不同资产 [Angular 5]
Different assets in cli config for ng serve and ng build [Angular 5]
当我使用 ng build
时是否可以使用不同的资产数组?
"assets": [
"assets",
"favicon.ico",
{
"glob": "**/*",
"input": "../externalDir",
"output": "./app/",
"allowOutsideOutDir": true
}
]
在我的例子中,当我使用 ng build
时,我只想构建这个:
"assets": [
"assets",
"favicon.ico"
]
我不认为可以选择制作特定于环境的资产。但是您可以在 angular-cli.json 中创建其他应用程序,这些应用程序基本上只是彼此的副本,但具有不同的资产。例如
// angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"name": "devApp",
"assets" : [
"assets",
"favicon.ico",
{
"glob": "**/*",
"input": "../externalDir",
"output": "./app/",
"allowOutsideOutDir": true
},
],
...
},
{
"root": "src",
"outDir": "dist",
"name": "prodApp",
"assets": [
"assets",
"favicon.ico"
],
...
}
]
现在您可以通过构建特定的 "app"
来构建不同的资产
// dev
ng build --app=0
// or
ng build --app=devApp
// prod
ng build --app=1
// or
ng build --app=prodApp
Angular cli docs 在多个应用程序上。
我的情况是在每个环境中包含不同的 robots.txt 文件。因此,在 src/environments
文件夹中我创建了两个文件:robots.txt
和 robots.prod.txt
。在 angular.json
中将其包含在 assets
数组中并使用 fileReplacements
如下(我只粘贴相关部分):
"architect": {
"build": {
"options": {
"assets": [
"src/assets",
{
"glob": "robots.txt",
"input": "src/environments/",
"output": "/"
}
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/robots.txt",
"with": "src/environments/robots.prod.txt"
}
]
}
}
}
}
我正在使用 @angular/cli: ~8.3.4
。
当我使用 ng build
时是否可以使用不同的资产数组?
"assets": [
"assets",
"favicon.ico",
{
"glob": "**/*",
"input": "../externalDir",
"output": "./app/",
"allowOutsideOutDir": true
}
]
在我的例子中,当我使用 ng build
时,我只想构建这个:
"assets": [
"assets",
"favicon.ico"
]
我不认为可以选择制作特定于环境的资产。但是您可以在 angular-cli.json 中创建其他应用程序,这些应用程序基本上只是彼此的副本,但具有不同的资产。例如
// angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"name": "devApp",
"assets" : [
"assets",
"favicon.ico",
{
"glob": "**/*",
"input": "../externalDir",
"output": "./app/",
"allowOutsideOutDir": true
},
],
...
},
{
"root": "src",
"outDir": "dist",
"name": "prodApp",
"assets": [
"assets",
"favicon.ico"
],
...
}
]
现在您可以通过构建特定的 "app"
来构建不同的资产// dev
ng build --app=0
// or
ng build --app=devApp
// prod
ng build --app=1
// or
ng build --app=prodApp
Angular cli docs 在多个应用程序上。
我的情况是在每个环境中包含不同的 robots.txt 文件。因此,在 src/environments
文件夹中我创建了两个文件:robots.txt
和 robots.prod.txt
。在 angular.json
中将其包含在 assets
数组中并使用 fileReplacements
如下(我只粘贴相关部分):
"architect": {
"build": {
"options": {
"assets": [
"src/assets",
{
"glob": "robots.txt",
"input": "src/environments/",
"output": "/"
}
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/robots.txt",
"with": "src/environments/robots.prod.txt"
}
]
}
}
}
}
我正在使用 @angular/cli: ~8.3.4
。