mah*_*han 6 javascript reactjs vite
I have a stylesheet in css folder and a few fonts in fonts folder. fonts and css folders are in the same directory.
|-fonts
| |--- a.woff
| |-- b.woff2
|
|-css
|--- typography.css
Run Code Online (Sandbox Code Playgroud)
I have used a.woff and b.woff2 in typography.css like this:
@font-face {
font-family: "basis-pro";
src: url("../fonts/a.woff2") format("woff2"),
url("../fonts/b.woff") format("woff");
font-style: normal;
font-weight: bold;
font-display: swap;
}
Run Code Online (Sandbox Code Playgroud)
I have changed base, rollupOptions.outPut and outDir of vite.config.js.
export default defineConfig({
base: "./",
plugins: [react()],
build: {
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
var info = assetInfo.name.split(".");
var extType = info[info.length - 1];
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
extType = "img";
} else if (/woff|woff2/.test(extType)) {
extType = "fonts";
}
return `static/${extType}/[name]-[hash][extname]`;
},
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
},
},
outDir: "./../backend/src/main/resources/static/app/",
},
});
Run Code Online (Sandbox Code Playgroud)
All of the assets have correct path excepts fonts when building the app.
fonts are generated in fonts and css files are genereted in css folder. But the two fonts in a css file has wrong path.
@font-face {
font-family: "basis-pro";
src: url("./a.woff2") format("woff2"),
url("./b.woff") format("woff");
font-style: normal;
font-weight: bold;
font-display: swap;
}
Run Code Online (Sandbox Code Playgroud)
It must be like the following as my assets has the same folder structure as the above (folder structure).
@font-face {
font-family: "basis-pro";
src: url("../fonts/a.woff2") format("woff2"),
url("../fonts/b.woff") format("woff");
font-style: normal;
font-weight: bold;
font-display: swap;
}
Run Code Online (Sandbox Code Playgroud)
How to fix this issue?
| 归档时间: |
|
| 查看次数: |
6429 次 |
| 最近记录: |