The issue you're facing is that the webfonts are not being copied to the public/build/webfonts directory when you run npm run build with Vite. To resolve this, you can manually configure Vite to copy the webfonts to the desired location during the build process.
Here's how you can do it:
-
Install the
copypackage as a dev dependency by running the following command in your project directory:npm install --save-dev copy -
In your
vite.config.jsfile, import thecopyfunction from thecopypackage:import { defineConfig } from 'vite'; import copy from 'copy'; -
Add a
buildproperty to yourvite.config.jsfile and configure theonEndhook to copy the webfonts to the desired location:export default defineConfig({ // ...existing configuration... build: { // ...existing build configuration... onEnd: () => { copy('node_modules/@fortawesome/fontawesome-free/webfonts', 'public/build/webfonts', (err) => { if (err) { console.error(err); } else { console.log('Webfonts copied successfully!'); } }); }, }, }); -
Save the
vite.config.jsfile.
Now, when you run npm run build, Vite will copy the webfonts from node_modules/@fortawesome/fontawesome-free/webfonts to public/build/webfonts after the build process is complete.
Note: Make sure the paths specified in the copy function match the actual paths of the webfonts in your project.
Let me know if you have any further questions!