Fontawesome is not working when project is built with grunt

前端 未结 15 1157
余生分开走
余生分开走 2020-12-02 07:50

I\'m using the font library font awesome. It works when the project is not built/uglified with grunt.

But when I\'m building the project with grunt it\'s not workin

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 08:00

    I was having the very same problem. I took a look a the bower.json file for font-awesome and found this:

    {
      "name": "font-awesome",
      "description": "Font Awesome",
      "keywords": [],
      "homepage": "http://fontawesome.io",
      "dependencies": {},
      "devDependencies": {},
      "license": ["OFL-1.1", "MIT", "CC-BY-3.0"],
      "main": [
        "less/font-awesome.less",
        "scss/font-awesome.scss"
      ],
      "ignore": [
        "*/.*",
        "*.json",
        "src",
        "*.yml",
        "Gemfile",
        "Gemfile.lock",
        "*.md"
      ]
    }
    

    There was no reference to the "font-awesome.css" in the "main" array. Perhaps, like me, you're not using SASS or LESS for styling. So no styles are being added for font-awesome. I modified the json file as follows:

    {
      "name": "font-awesome",
      "description": "Font Awesome",
      "keywords": [],
      "homepage": "http://fontawesome.io",
      "dependencies": {},
      "devDependencies": {},
      "license": ["OFL-1.1", "MIT", "CC-BY-3.0"],
      "main": [
        "less/font-awesome.less",
        "scss/font-awesome.scss",
        "css/font-awesome.css",
        "fonts/fontawesome-webfont.tff",
        "fonts/fontawesome-webfont.woff",
        "fonts/fontawesome-webfont.woff2"
      ],
      "ignore": [
        "*/.*",
        "*.json",
        "src",
        "*.yml",
        "Gemfile",
        "Gemfile.lock",
        "*.md"
      ]
    }
    

    I saved and ran grunt serve, and now my font-awesome icons show up.

    Hope this helps.

提交回复
热议问题