首页 文章

Angular将图像复制到其根文件夹

提问于
浏览
1

我将我的资产图像保存在'assets / images / icons'文件夹下,在我的style.scss文件中,我有'background:url(assets / images / icons / searchbox_magnifier.png)no-repeat#f5f5f5;'等规则 . 但是在进行 生产环境 构建时,Angular正在将所有这些文件复制到其根文件夹并根据它更改style.scss规则,如“background:url(searchbox_magnifier.png)”,请参阅附加的图像 .

style.scss production build

如何避免这个问题?

1 回答

  • 0

    在您的 .angular-cli 文件中,请找到:

    "assets": [
       "assets",
       "favicon.ico"
    ]
    

    作为你的默认值 .

    根据 ./node_modules/@angular/cli/lib/config/schema.json ,资产接受:

    "assets": {
            "type": "array",
            "description": "List of application assets.",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "properties": {
                    "glob": {
                      "type": "string",
                      "default": "",
                      "description": "The pattern to match."
                    },
                    "input": {
                      "type": "string",
                      "default": "",
                      "description": "The dir to search within."
                    },
                    "output": {
                      "type": "string",
                      "default": "",
                      "description": "The output path (relative to the outDir)."
                    },
                    "allowOutsideOutDir": {
                      "type": "boolean",
                      "description": "Allow assets to be copied outside the outDir.",
                      "default": false
                    }
                  },
                  "additionalProperties": false
                }
              ]
            },
    

    因此,在您的情况下,请尝试更改为:

    "assets": [
       ...
       {
          "glob": "**/*",
          "input": "./assets",
          "output": "assets/"
       }
     ]
    

    或者你想要的任何地方 .

相关问题