Font file integration with webpack implementation is smooth sailing

I'm having trouble getting my font to load while using webpack2 with express. The JavaScript file is working fine, but the font just won't serve. Can someone please help me troubleshoot this issue? Here's a snippet of my webpack.config:

const devConfig = {
devtool: '#source-map',
entry: [
    './public/js/entry.js',
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client'
]
,
output: {
    filename: './js/main.js',
    path: '/',
    publicPath: publicPath
},
plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
],
module: {
    rules: [
        {
            test: /\.s(a|c)ss$/,
            use: [{
                loader: "style-loader" // creates style nodes from JS strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        {
            test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
            loader: 'file-loader?'
        }
    ]
}

};

Within my SCSS file, I have the following reference:

src: url('../font-files/firasans-extralightitalic-webfont.woff2') format('woff2'), url('../font-files/firasans-extralightitalic-webfont.woff') format('woff');

} and my directory structure looks like this: https://i.sstatic.net/k4Bi5.png

However, I keep receiving this error message:

Module not found: Error: Can't resolve '../font-files/firasans-extralightitalic-webfont.woff2'

Can anyone point out what might be causing this issue? I've noticed some people include their fonts within the JavaScript file, but I prefer not to do it that way.

Answer №1

After struggling for a few more hours, I finally figured out how to get it to function properly. the trick is to use relative paths in @font-face, but the path should be relative to the entry point. In my case, the entry point is style.sass, so I ended up writing this

src: url('./font-files/firasans-extralightitalic-webfont.woff2')

with this adjustment, the files are now being resolved correctly

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

Unwanted overlapping of JavaScript image slideshow animation on top of the website's header

Situation/ Issue The picture slide animation box on my website is positioned just below the fixed header. The problem arises when I try to change the image using the left and right arrows. During the transition, a part of the hidden image becomes visible a ...

I'm currently working on a course assignment and I've encountered an issue where nothing happens when I try to execute node

Having trouble with the readline for input execution. Any helpful hints or tips? I've been using it in the same file for all exercises, checked stackoverflow too but realized I'm on Windows. This is my code const { rejects } = require('asse ...

Currently, I am in the process of developing an Express application that includes a user-friendly login form for individuals

I am currently developing an Express application with a login form. For the password encryption, I have implemented bcryptjs and made sure to include the secret_key in my git ignore file. My project consists of two controller files - one for users and anot ...

Input field with ruled lines beneath each line of text

Can you assist in creating a textarea that displays lines under each row of text similar to the example shown in the image below? ...

Prevent Keyboard Interactions on Web Pages with CSS or JavaScript

There is a <div> element on my page. <div id="ViewActivitydiv" > @await Component.InvokeAsync("QuestionAnswers", new { activityQuestionAnswersList = Model.ActivityQuestionAnswers?.ToList() }) </div> I need to restrict us ...

No output is displayed when using Node Cheerio

Currently, I'm facing challenges with web scraping. Here is the code snippet causing trouble: const request = require('request'); const cheerio = require('cheerio'); request('https://firestorm-servers.com/en/community/armo ...

How to implement a for loop within a Vue.js method

Within Vuejs, I have a method that updates multiple variables based on user selection. methods: { updateChart(){ this.chart1.series[1].data = [this.$store.state.selectedcities[0].value[1]]; this.chart1.series[2].data = [this.$store.state.selecte ...

I encountered an SyntaxError while working with Ionic. The error message reads: "Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)."

Here's the code that is causing me trouble: this.http.get('http://localhost/....) .map((res) => res.json()) .subscribe(( this.navCtrl.push(OtpPage,{mobileno:this.mobile}); }, (err) => { console.log(err ...

In Visual Studio, make sure to include a reference to AngularJS.min.js within another JavaScript file

In my AngularJS app, I am utilizing Visual Studio with separate folders. The AngularJS-min.js file is located in a different folder. My query is how can I correctly reference the AngularJS-min.js file in my app's JavaScript file to enable auto-suggest ...

Is it possible to make jQuery dialog text behave like a JavaScript prompt?

Hello there, I have a query! I'm looking to allow users to easily copy text within a dialog window by simply pressing CTRL + C. Is this possible, and if so, how can it be achieved? An instance of this functionality is seen in the javascript alert pr ...

Determine if a generated number matches the previous one using Javascript

On my webpage, I have multiple tiles that are being manipulated with JavaScript to switch a class on a random tile every 2 seconds. I am interested in implementing a check so that the same tile is not toggled twice consecutively. I attempted the followin ...

Guide to importing a .obj file into an electron-vue webpack project using vue-3d-model

Greetings to the community, I have a question for you all! My name is Victor, and I am delving into the world of programming on my own. I hope that I can articulate my issue clearly with sufficient details. I am working on an application using electron + ...

Sort out the DIVs containing card elements

Is there a way to filter DIVs containing cards based on their categories? I seem to be encountering an issue where the filtering only works with letters. I suspect the problem lies in the Javascript code, but I can't pinpoint it. Can you help me ident ...

Issue encountered while attempting to create directories in node.js using express and multer

I am currently working on setting up a server using node.js with express and multer. The goal is to send an identifier along with 12 photos to be saved in a specific folder. I am implementing a multipart formdata for this purpose, but I am encountering an ...

What is the reason behind fullPage.js only displaying the first page while hiding all others?

My website development is currently hindered by an issue with fullPage js. Only the first page is visible when using fullPage js, even though the links are properly set up on the dev site. As a result, I have to disable fullpage in order to make any progre ...

Exploring the World of PHP, MySQL, and AJAX

Recently, I came across an issue where I needed to extract values from a MySQL database using JavaScript. What I intended to achieve was to dynamically add a div element when a PHP page is loaded for editing information. The plan was to populate this div w ...

Is it possible to view JavaScript methods in the watch window of IE's debugger?

Can I view custom methods in the IE developer toolbar's watch window? For example, if I have a global function named hello, can I locate it within the DOM? function hello() { alert("hello"); } If so, where in the watch window would I find them? ...

Customizing the add row functionality in material table

Before the add row in the editable table opens, I would like to run a function. https://i.sstatic.net/7kVVL.png It is important for me to execute a specific function before this user interface becomes visible. (such as console.log('Hello')) Here ...

Troubleshooting problem with formatting and default value in MUI X DatePicker

I'm encountering a problem and struggling to find a solution. The default format for displaying dates in the MUI X DatePicker (with Material UI) is: Fri Oct dd yyyy HH:MM:SS GMT+HHMM (name of timezone here) However, I need to pass a date in the forma ...

Ways to transfer data between Angular controller and jQuery

Looking for some guidance on how to toggle between two HTML divs based on user input validation using an Angular controller and jQuery animations. Each div contains input fields that need to be validated before moving on to the next stage. Here is a simpli ...