无法从React App中的CSS文件访问我的公用文件夹

问题描述

每次尝试访问公用文件夹中的文件时,我都会收到以下错误消息。

./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
Error: Can't resolve '/assets/fonts/PlantinMTProRg.woff' in 'C:\Users\User\Desktop\NewPage\webpage\src'

如您所见,我正在尝试从位于src文件夹中的index.css调用一种字体。

我将其称为:

@font-face {
  font-family: 'PlantinMTPro';
  src: local('plantin_mt_pro'),url(/assets/fonts/PlantinMTProRg.woff) format('truetype');
}

但是到目前为止还没有运气。图片有相同的问题。

有什么想法吗?

谢谢!

解决方法

在index.html中,必须从公共目录链接index.css

for (i in seq_len(n)[nrows < nr]) {
    xi <- vlist[[i]]
    if (nrows[i] > 0L && (nr%%nrows[i] == 0L)) {
        xi <- unclass(xi)
        fixed <- TRUE
        for (j in seq_along(xi)) {
            xi1 <- xi[[j]]
            if (is.vector(xi1) || is.factor(xi1)) 
              xi[[j]] <- rep(xi1,length.out = nr)
            else if (is.character(xi1) && inherits(xi1,"AsIs")) 
              xi[[j]] <- structure(rep(xi1,length.out = nr),class = class(xi1))
            else if (inherits(xi1,"Date") || inherits(xi1,"POSIXct")) 
              xi[[j]] <- rep(xi1,length.out = nr)
            else {
              fixed <- FALSE
              break
            }
        }
        if (fixed) {
            vlist[[i]] <- xi
            next
        }
    }
    stop(gettextf("arguments imply differing number of rows: %s",paste(unique(nrows),collapse = ",")),domain = NA)
}

从那里,您需要找出正确的URL才能到达您所说的src文件中的字体系列。

<link rel="stylesheet" href="%DIR%/NewPage/webpage/src/index.css">

此外,我注意到您使用的是truetype格式。仅在导入.ttf文件时使用。在这种情况下,请使用@font-face { font-family: 'PlantinMTPro'; src: local('plantin_mt_pro'),url(/assets/fonts/PlantinMTProRg.woff) format('woff'); }

如果您要支持多种浏览器,则可能需要在此处添加一些更改