When executing npm run build, the fonts are not displayed properly in Vite

I'm running 'npm run build' to compile my project, and then I use the 'npm run preview' command to view it. However, some images that I've set as background images in my SCSS file are not showing up. The same issue occurs with a font family.

Here is my 'package.json' file:


{
  "name": "project-name",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "devDependencies": {
    "sass": "^1.52.3",
    "vite": "^2.9.9"
  }
}

And here is my 'vite.config.js' file:


/* Do not edit this file */
import { defineConfig } from 'vite'

export default defineConfig({
    build: {
        minify: false
    }
});

In my SCSS, it seems like Vite doesn't understand the '../../../ directory when compiling:


@font-face {
    font-family: "CustomFont";
    src: url("../../../src/assets/fonts/Marcheile-Bold-Condensed.woff") format("woff"),
    url("../../../src/assets/fonts/Marcheile-Bold-Condensed.otf") format("opentype"),
    url("../../../src/assets/fonts/Marcheile-Bold-Condensed.woff2") format("woff2");
}

Answer №1

Make sure your assets are located in the same folder as your codebase. It is assumed that they should be in the dist directory based on your configuration in vite.config.js

Consider setting the publicDir parameter by visiting

The publicDir option specifies a directory where static assets can be accessed directly. These files will be served at the root path during development and copied to the output directory when building the project. They are served or copied without any modifications. You can use an absolute file system path or a path relative to the project root.

Adjust the url within your scss files (remove any unnecessary "../../.." references)

Refer to the dist directory for further information

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a form submission event through Asp.net code behind

Is there a way to change the onsubmit parameter of a form in an asp.net project, specifically from the master page code behind of a child page? I am interested in updating the form value so that it looks like this: <form id="form1" runat="server" onsu ...

Changing the color of the timePicker clock in material-ui: a step-by-step guide

I have been attempting to update the color of the time clock in my timeInput component (material-ui-time-picker) for material-ui, but unfortunately, it is not reflecting the change. Here is the code I am using: <TimeInput style ={heure} ...

The object function router(req, res, next) is encountering an error as it does not contain the required method for handling the request

I am trying to add a new row to my MySQL database, but I encountered an error message. Here is the scenario: I have set up Passport and hjs in my project. I am passing form data from app.js to a JavaScript file where I aim to insert the data. Object funct ...

Unable to interact with options in a dropdown menu while utilizing selenium

As a newcomer to the world of web scraping with Python using Selenium, I am trying to extract information on tennis players from the website "https://www.itftennis.com/en/players/". The challenge I am facing is related to navigating a drop-down list of res ...

Transform the input value into a string

Struggling with converting an input value into a string. HTML: <input type="text" placeholder="Email Ex: john123" id="emailinput"> <input type="text" placeholder="Domain Ex: @gmail.com" id="domaininput"> JS: let emailVal = document.getElem ...

The nested navigation link disappears suddenly on Internet Explorer 9

This query closely resembles another issue: Nested menu keeps vanishing on IE 8 & 9. However, the solution provided is quite limited. Why do my nested menus disappear before I can reach them with my cursor unless I move it swiftly? This peculiar behavi ...

Tips for real-time editing a class or functional component in Storybook

Hey there, I am currently utilizing the storybook/react library to generate stories of my components. Everything has been going smoothly so far. I have followed the guide on https://www.learnstorybook.com/react/en/get-started and added stories on the left ...

How can I distinguish between the multiple lists returned by the Web API and store them in separate arrays?

My web API returns multiple lists, such as employersList and locationsList. Here is the current code I am using: items = []; constructor(private http: HttpClient) {} getMember(){ this.http.get('http://apirequest').toPromise().then(da ...

What causes images to expand automatically when selected in my JavaScript gallery?

I am struggling with a simple JS gallery of images where I want to display a large image at the top and small thumbnails below it. The issue I am facing is that when I hover over an image in the thumbnail section, the big image changes as expected. However ...

Authenticating and authorizing a client-side web application with a Remote NodeJS API integrating Passport.js

Displayed in the diagram below, there is an independent API Project operating on a server with a specific port, for example 3001, and a Web App running on a different server with another port, like 3002. https://i.sstatic.net/ovvAZ.png Running on port 30 ...

React conditional statement within a map function embedded in a JSX element

Below is the function I have created to generate tabbed items: function ConstructTabs(props) { const tabs = props.tabs; const makeTabs = tabs.map((tab, index) => { <React.Fragment> <input className="input-tabs" id ...

Acquire information from the user interface and display it in a highcharts chart using Angular 5

Currently, I am utilizing an npm package for chart creation, which can be found at the following link: https://www.npmjs.com/package/angular-highcharts I have a specific interface set up and I aim to extract values from this interface to populate a line g ...

Displaying Mustache.js in an HTML template

I attempted to integrate mustache.js into my web application. After loading the mustache.js file, I included the following script in my code: <script type="text/javascript> $(document).ready(function () { var person = { first ...

Quasar is having trouble locating some additional Quasar features, specifically the material-icons, roboto font css, and polyfills

Whenever I initiate quasar dev, the following message pops up. The setup is pretty standard using the pwa template. The required dependencies are missing: quasar-extras/material-icons/material-icons.css in ./.quasar/client-entry.js quasar-extras/roboto ...

Issue with React-Axios: File data being sent to Node server is undefined

My current challenge involves uploading a single file and saving it in a specific folder within my app directory. While I can successfully choose a file on the frontend and update the state of the Uploader component, I encounter an issue when sending a POS ...

Using InputAdornment with MUI AutoComplete causes the options list to disappear

I created a custom AutoComplete component with the following structure: https://i.sstatic.net/xcv9y.png <Autocomplete freeSolo size="small" id="filter-locks-autocomplete" options={json_list ? json_list : []} groupBy={(optio ...

Tips for designing a customizable color scheme for your website

Are you looking to implement a changeable color scheme for your website? Getting started can be daunting, especially if you're unfamiliar with sass. Would appreciate it if anyone could share some helpful tutorials or links? For example: example ...

What is the best method to showcase data retrieved from the backend in a Node.js application using the combination of Jade, Angular

I'm planning to create a single-page web application with the following tech stack: Backend: Node.js (express) Frontend: Jade + AngularJS Database: Mongoose When sending data to the backend as a form, I found this helpful post on ExpressJS Angular ...

What is the best way to handle code versioning using Django, Angular2, and Webpack?

Currently, I am utilizing Django in conjunction with Angular 2 and Webpack. Within Django, I have set up a URL to display my application at http://example.com/user/beta. Initially, my index.html file is rendered, which contains my Angular 2 components. Wit ...

Content width exceeds body width

Having an issue with body width that seems strange. Check out this fiddle link to see for yourself. <div class="topbar" style="width:100%; background:#000; color:#fff"> <div class="container" style="width:970px; margin:0 auto;">Lorem ipsum ...