【发布时间】:2019-05-09 15:26:06
【问题描述】:
我正在使用 gatsby-plugin-sass 来包含我的 sass 文件。我有一个导入_typography.sass 的web-animations.sass 文件。我的_typography.sass 有这样的字体声明:
@font-face
font-family: 'BrandonPrinted'
src: url(../../global/fonts/brandonprinted-one-webfont.eot)
src: url(../../global/fonts/brandonprinted-one-webfont.eot?#iefix) format('embedded-opentype'), url(../../global/fonts/brandonprinted-one-webfont.woff) format('woff'), url(/src/page-assets/global/fonts/brandonprinted-one-webfont.ttf) format('truetype')
当我运行gatsby develop 时,我得到了这个错误:
ERROR Failed to compile with 2 errors 19:51:15
These relative modules were not found:
* ../../global/fonts/brandonprinted-one-webfont.eot in ./~/css-loader!./~/sass-loader?{"plugins":[]}!./src/page-assets/work-ive-done/subpages/web-animations/styles/web-animations.sass
* ../../global/fonts/brandonprinted-one-webfont.woff in ./~/css-loader!./~/sass-loader?{"plugins":[]}!./src/page-assets/work-ive-done/subpages/web-animations/styles/web-animations.sass
似乎字体 url 路径被解释为相对于 web-animations.sass 而不是相对于 _typography.sass,因为如果我将 web-animations.sass 向上移动两个级别,那么这个错误就会消失。
有没有办法让_typography.sass 查找相对于其自身位置的字体文件?
【问题讨论】:
-
url 被解释为相对于您的网络根目录。
-
gatsby 是否使用 webpack 来构建你的模块?
-
是的,Gatsby 使用 webpack。
-
我猜你的入口点在 ./src/page-assets 中,对吗?
-
我不确定...这是该插件的 Git 存储库:github.com/gatsbyjs/gatsby/tree/master/packages/… 我已经浏览过它,但还没有任何反应。