Angular CLI 6:背景图像问题

时间:2018-05-25 22:12:09

标签: angular webpack background-image angular-cli angular-cli-v6

Angular CLI 6.0.3在css中将sass代码background-image: url(assert/folder1/x.png);解析为background-image: url(x.png);

我有很多这样的地方

...
background-image: url(assert/folder1/x.png);
...
background-image: url(assert/folder2/x.png);
...
background-image: url(assert/folder3/x.png);
...

但所有这些定义都变得像

...
background-image: url(x.png);
...
background-image: url(x.png);
...
background-image: url(x.png);
...

这意味着所有班级都有相同的形象......

如何强制Angular CLI留下图像路径?

UPD:此问题仅对开发模式有影响

2 个答案:

答案 0 :(得分:1)

解决方案是添加“ outputHashing ”属性,并带有“媒体”值。

/* angular.json */
{
  ...
  "projects": {
     ...
     "your-project": {
        ...
        "architect": {
           ...
           "build": {
             ...
             "options": {
                ...
                "outputHashing": "media",
                ...
             }
           }
        }
     }
  }
}

答案 1 :(得分:0)

这对我有用,您只能使用background:url()代替background-image:url()background: url('/assets/images/gc1.jpg')