vue-cli搭建的项目,加入bootstrap后,fonticon没有正确显示出来

dev的时候没有问题,build之后出现问题

http://172.16.0.10:8085/backend/dist/static/css/static/fonts/glyphicons-halflings-regular.448c34a.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
http://172.16.0.10:8085/backend/dist/static/css/static/fonts/glyphicons-halflings-regular.fa27723.woff Failed to load resource: the server responded with a status of 404 (Not Found)
http://172.16.0.10:8085/backend/dist/static/css/static/fonts/glyphicons-halflings-regular.e18bbf6.ttf Failed to load resource: the server responded with a status of 404 (Not Found)

webpack关于这里的编译和路径没有改动:

{
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url',
        query: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }

ps:其它插件的fonticon没有此问题



2016年10月12日 12:58:31
找到问题所在了。
因为bootstrap等一些插件他们css中,引入font的路径为../font/.....
然而webpack的配置中:为:

{
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url',
        query: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }

所以只要加一个query对象:

{
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url',
        query: [{
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        },
        {
          limit: 10000,
          name: utils.assetsPath('../fonts/[name].[hash:7].[ext]')
        }]
      }

问题就解决了!

阅读 6.9k
2 个回答

遇到同样的问题,尝试按照你的方案解决,但是新版的webpack中似乎不支持把query或者options配置成数组,只能是对象或者字符串,最后按照https://github.com/vuejs-temp... 中bsqql123这个哥们的办法解决的,修改utils.js

找到问题所在了。
因为bootstrap等一些插件他们css中,引入font的路径为../font/.....
然而webpack的配置中:为:

{

    test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
    loader: 'url',
    query: {
      limit: 10000,
      name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
    }
  }

所以只要加一个query对象:

{

    test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
    loader: 'url',
    query: [{
      limit: 10000,
      name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
    },
    {
      limit: 10000,
      name: utils.assetsPath('../fonts/[name].[hash:7].[ext]')
    }]
  }

问题就解决了!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题