[英]Dynamically link static css in html
I have a css file that I want to link in my html (served from my public directory).我有一个 css 文件,我想在我的 html 中链接(从我的公共目录提供)。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="assets/loadSomeFonts.css"></head> <--- this is served from public
</head>
<body style="margin: 0px">
<div id="root"></div>
</body>
</html>
This css has references other assets as url
:这个 css 引用了其他资产作为
url
:
url("/assets/fontsFolder/myfont.ttf")
When I'm developing my public path has a different url than in production - how can I differentiate between them using webpack?当我开发公共路径时,其 url 与生产中的 url 不同 - 如何使用 webpack 区分它们?
Add the full path of your files in html.在 html 中添加文件的完整路径。 if assets folder is in public folder then you have to add public as well
如果assets文件夹在public文件夹中,那么你也必须添加public
<link rel="stylesheet" href="public/assets/loadSomeFonts.css">
I ended up using create-react-app
with the PUBLIC_PATH
variable since it seems the easiest way to do this.我最终将
create-react-app
与PUBLIC_PATH
变量一起使用,因为这似乎是最简单的方法。
Could always copy the logic from there and use it in another project总是可以从那里复制逻辑并在另一个项目中使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.