问题
I'm using Parcel for bundling and I want to include custom font to my project
In my SCSS
@font-face {
font-family: "Storytella";
src: url("./fonts/Storytella.otf") format("otf");
}
Then I'm using it somewhere like thisfont-family: 'Storytella', serif;
package.json
{
"name": "pr",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"normalize.css": "^8.0.1",
"parcel-bundler": "^1.12.3"
},
"devDependencies": {
"node-sass": "^4.12.0",
"parcel-plugin-static-files-copy": "^2.2.0",
"pug": "^2.0.4"
},
"scripts": {
"dev": "parcel index.pug",
"build": "parcel build index.pug --out-dir dist"
},
"staticFiles": {
"staticPath": "dist",
"watcherGlob": "**"
},
"keywords": [],
"author": "",
"license": "ISC"
}
While running npm run dev
the font is placed inside dist
folder but the font itself doesn't get loaded to the page.
I get no errors in Networks in Chrome or anything like this but also no loading of the font.
回答1:
in index.html you need link fonts.css like this
<link rel="stylesheet" type="text/css" href="/styles/fonts.css" />
in fonts.css
@font-face {
font-family: "Storytella";
src: url("./fonts/Storytella.otf") format("otf");
}
body {
font-family: 'Storytella', serif;
}
来源:https://stackoverflow.com/questions/57279163/how-to-load-font-from-font-face-with-parcel