获取Angular8中assets文件夹中不同构建版本的徽标。

huangapple go评论73阅读模式
英文:

Get different builds for logo in assets folder in Angular8

问题

在资产文件夹中有两个城市都有同名的 logo.jpeg 图片。当我说 "build: london" 时,我希望伦敦的 logo 出现在项目中。我不想像这样给出路径:"img source in assets / london / logo.jpeg or assets / paris / logo.jpeg"。我的 "build: city" 应该根据城市的 logo 来显示。

app.component.html

<div class="condition1">
  <img src="/assets/logo.jpeg">
</div>

angular.json

"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "outputPath": "dist",
      "index": "src/index.html",
      "main": "src/main.ts",
      "polyfills": "src/polyfills.ts",
      "tsConfig": "tsconfig.app.json",
      "aot": false,
      "styles": [],
      "scripts": []
    },
    "configurations": {
      "london": {
        "assets": [
          { "glob": "*.jpeg", "input": "src/assets/london", "output": "assets"}
        ],
        "fileReplacements": [
          {
            "replace": "src/environments/environment.ts",
            "with": "src/environments/environment.prod.ts"
          }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true,
        "budgets": [
          {
            "type": "initial",
            "maximumWarning": "2mb",
            "maximumError": "5mb"
          },
          {
            "type": "anyComponentStyle",
            "maximumWarning": "6kb",
            "maximumError": "10kb"
          }
        ]
      },
      "paris": {
        "assets": [
          { "glob": "*.jpeg", "input": "/src/assets/paris/", "output": "assets"}
        ],
        "fileReplacements": [
          {
            "replace": "src/environments/environment.ts",
            "with": "src/environments/environment.prod.ts"
          }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true,
        "budgets": [
          {
            "type": "initial",
            "maximumWarning": "2mb",
            "maximumError": "5mb"
          },
          {
            "type": "anyComponentStyle",
            "maximumWarning": "6kb",
            "maximumError": "10kb"
          }
        ]
      }
    }
  }
}
英文:

There is a logo.jpeg with the same name for 2 cities in asset folder. And when I say build: london, I want the london logo to come on the project. I do not want to give like that "img source in assets / london / logo.jpeg or assets / paris / logo.jpeg". my build: city should come according to the city's logo

app.component.html

&lt;div class=&quot;condition1&quot;&gt;
&lt;img src=&quot;/assets/logo.jpeg&quot;&gt;
&lt;/div&gt;

angular.json

&quot;root&quot;: &quot;&quot;,
&quot;sourceRoot&quot;: &quot;src&quot;,
&quot;prefix&quot;: &quot;app&quot;,
&quot;architect&quot;: {
&quot;build&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:browser&quot;,
&quot;options&quot;: {
&quot;outputPath&quot;: &quot;dist&quot;,
&quot;index&quot;: &quot;src/index.html&quot;,
&quot;main&quot;: &quot;src/main.ts&quot;,
&quot;polyfills&quot;: &quot;src/polyfills.ts&quot;,
&quot;tsConfig&quot;: &quot;tsconfig.app.json&quot;,
&quot;aot&quot;: false,
&quot;styles&quot;: [
],
&quot;scripts&quot;: []
},
&quot;configurations&quot;: {
&quot;london&quot;: {
&quot;assets&quot;: [
{ &quot;glob&quot;: &quot;*.jpeg&quot;, &quot;input&quot;: &quot;src/assets/paris&quot;, &quot;output&quot;: &quot;assets&quot;}
],
&quot;fileReplacements&quot;: [
{
&quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
&quot;with&quot;: &quot;src/environments/environment.prod.ts&quot;
}
], &quot;optimization&quot;: true,
&quot;outputHashing&quot;: &quot;all&quot;,
&quot;sourceMap&quot;: false,
&quot;extractCss&quot;: true,
&quot;namedChunks&quot;: false,
&quot;aot&quot;: true,
&quot;extractLicenses&quot;: true,
&quot;vendorChunk&quot;: false,
&quot;buildOptimizer&quot;: true,
&quot;budgets&quot;: [
{
&quot;type&quot;: &quot;initial&quot;,
&quot;maximumWarning&quot;: &quot;2mb&quot;,
&quot;maximumError&quot;: &quot;5mb&quot;
},
{
&quot;type&quot;: &quot;anyComponentStyle&quot;,
&quot;maximumWarning&quot;: &quot;6kb&quot;,
&quot;maximumError&quot;: &quot;10kb&quot;
}
]},
&quot;paris&quot;: {
&quot;assets&quot;: [
{ &quot;glob&quot;: &quot;*.jpeg&quot;, &quot;input&quot;: &quot;/src/assets/paris/&quot;, &quot;output&quot;: &quot;assets&quot;}
],
&quot;fileReplacements&quot;: [
{
&quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
&quot;with&quot;: &quot;src/environments/environment.prod.ts&quot;
}
],
&quot;optimization&quot;: true,
&quot;outputHashing&quot;: &quot;all&quot;,
&quot;sourceMap&quot;: false,
&quot;extractCss&quot;: true,
&quot;namedChunks&quot;: false,
&quot;aot&quot;: true,
&quot;extractLicenses&quot;: true,
&quot;vendorChunk&quot;: false,
&quot;buildOptimizer&quot;: true,
&quot;budgets&quot;: [
{
&quot;type&quot;: &quot;initial&quot;,
&quot;maximumWarning&quot;: &quot;2mb&quot;,
&quot;maximumError&quot;: &quot;5mb&quot;
},
{
&quot;type&quot;: &quot;anyComponentStyle&quot;,
&quot;maximumWarning&quot;: &quot;6kb&quot;,
&quot;maximumError&quot;: &quot;10kb&quot;
}
]
}
}
},

答案1

得分: 0

你可以使用与此文章描述的相同方法。
例如,您可以为每个城市创建一个资产文件夹,然后可以为每个城市定义一个应用程序,唯一的区别是它们使用的资产文件夹不同。

英文:

You can use the same approach that this article describes.
For example, you can have an assets folder for each city, and then you can define an app for each city where the only difference is the assets folder they use.

huangapple
  • 本文由 发表于 2020年1月6日 22:32:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定