The issue seems to be related to the way Vite resolves paths. One solution is to use the vite-plugin-legacy plugin to handle legacy assets like fonts. Here's how to use it:
- Install the plugin:
npm install vite-plugin-legacy --save-dev
- Update your
vite.config.jsfile to include the plugin:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue2';
import legacy from '@vitejs/plugin-legacy';
export default defineConfig({
plugins: [
vue(),
legacy({
targets: ['defaults', 'not IE 11']
})
]
});
- Update your
index.htmlfile to include the legacy assets:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My App</title>
<link rel="stylesheet" href="/assets/css/app.css" />
<!-- Include legacy assets -->
<script nomodule src="/assets/js/app.legacy.js"></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/assets/js/app.js"></script>
</body>
</html>
- Update your
app.jsfile to import the legacy assets:
import '/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf';
This should resolve the issue with the fonts not loading properly.