Astro Js @font-face import 构建错误替换

发布于 2025-01-14 11:06:02 字数 705 浏览 3 评论 0原文

我正在构建一个 Astro Js 项目,我不想从包含其自己的字体文件的依赖项导入 css 文件(用于图标):

// @icons/dist/.../index.css
@font-face {
    font-family: "font name";
    src: url("./icons.ttf") format("truetype"),
url("./icons.woff") format("woff"),
url("./icons.woff2") format("woff2");
}

构建时我有一个替换项,它不包含 dist 文件夹中的字体文件,编译后的CSS:

@font-face {
    font-family: 'font name';
    src: url(__VITE_ASSET__e6e97650__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('truetype'),
        url(__VITE_ASSET__bc194da8__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('woff'),
        url(__VITE_ASSET__c837e718__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('woff2');
}

有人遇到过这个问题并且知道如何解决吗?

I'm building an Astro Js project, I wan't to import a css file (for icons) from a dependency which include their own font files :

// @icons/dist/.../index.css
@font-face {
    font-family: "font name";
    src: url("./icons.ttf") format("truetype"),
url("./icons.woff") format("woff"),
url("./icons.woff2") format("woff2");
}

When building I have a replacement which is not including the font file in the dist folder, the compiled css :

@font-face {
    font-family: 'font name';
    src: url(__VITE_ASSET__e6e97650__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('truetype'),
        url(__VITE_ASSET__bc194da8__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('woff'),
        url(__VITE_ASSET__c837e718__$_?6cdb7df3dc807c5592752bbd5d1c724e__) format('woff2');
}

Does anyone had this issue and know how to resolve it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找个人就嫁了吧 2025-01-21 11:06:02

如果 icons.ttf 位于公共文件夹内,则 url 应为:url("/icons.ttf")

基本上,您需要删除点,以便它定位公共文件夹文件夹而不是包含 CSS 文件的文件夹。

If icons.ttf is inside the public folder, the url should be: url("/icons.ttf")

Basically you need to remove the dot so it target the public folder instead of the folder where you have the CSS file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文