html - @font-face 在安装 ParcelJS 后不工作

标签 html css sass font-face parceljs

我之前将 Gulp 设置为使用 Sass、Pug 和 Babel。字体加载正常。我切换到使用 Parcel现在它按预期工作,除了一件事。字体未加载。

这是 _fonts.sass 的全部内容:

@font-face
  font-family: "MyWebFont"
  src: url(../fonts/economica-regular-otf.eot)
  src: url(../fonts/economica-regular-otf.eot?#iefix) format("embedded-opentype"),
  url(../fonts/economica-regular-otf.woff2) format("woff2"),
  url(../fonts/economica-regular-otf.woff) format("woff"),
  url(../fonts/economica-regular-otf.ttf) format("ttf")

@font-face
  font-family: "MyWebFontBold"
  src: url(../fonts/economica-bold-otf.eot)
  src: url(../fonts/economica-bold-otf.eot?#iefix) format("embedded-opentype"),
  url(../fonts/economica-bold-otf.woff2) format("woff2"),
  url(../fonts/economica-bold-otf.woff) format("woff"),
  url(../fonts/economica-bold-otf.ttf) format("ttf")

body
  font-family: 'MyWebFont', 'Titillium Web', sans-serif
  text-rendering: auto
  text-rendering: geometricPrecision

文件夹结构如下:

/dist
/src
-- / pug
--- index.pug
-- / sass
--- _fonts.sass
--- _animations.sass
--- _blocks.sass
--- _elements.sass
--- styles.sass
-- / js
--- // all the scripts
-- / fonts
--- // all the fonts are here

您可以在此处("new"分支)找到元素文件:GitHub

最佳答案

我不久前解决了这个问题。

package.json 中,我将 build 脚本编辑为 "build": "parcel build src/pug/index.pug --public-url ./-d 距离”

然后我编辑了 _fonts.sass 所以 @font-face 不会进入目录。例如,src: url(../fonts/economica-regular-otf.eot) 变成了 src: url(./fonts/economica-regular-otf.eot).

我已经有一段时间没弄明白了,所以我不记得这背后的原因,但它确实有效。

关于html - @font-face 在安装 ParcelJS 后不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304800/

相关文章:

css - 无法摆脱 Navbar 元素的顶部/底部边距?

javascript - 通过 CSS 和 JS 的两个重叠图像

html - 将 Html 元素与 flex 属性对齐

javascript - 在循环中为该选择器的所有实例选择(在任何选择器中)特定选项后,暂时禁用该选项

css - 带有 bootstrap 4 的嵌套 flexbox 列在 firefox 上显示错误但在 chrome 上显示正常

SASS 函数变暗和变亮在使用颜色对象时不起作用

html - 如何完全去除边距并使 div 全宽

css - 如何在 3 列网格设置中拉伸(stretch)中间列

javascript - 如何编辑 Skype 联系我按钮 CSS?

javascript - 对 node_modules 中文件的本地更改(Angular 2)