Load fonts with Webpack and font-face
After trying a lot of stuff the next loader made the work. Instead of file-loader, I used url-loader . You need url-loader installed.
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
How to load fonts from LESS file with Webpack 5?
I was able to fix this issue by adding:
*{font-family:Gibson;}
to my bootstrap.less
file.
I'm really uncertain this is the best way to do this, but it does work.
Webpack 5 font asset issue, no error but no font either
When you're defining a @font-face
declaration, on the font-family
property, you must only write a string indicating how you will reference the font in your later styles.
In other words, I erroneously included "sans-serif" after "Yusei Magic" on the font-family
property. This didn't throw an error, but it's incorrect CSS and thus was the source of my error. Thanks for anyone who chimed in!
Can’t import font-face using webpack-4 file-loader
SOLVED!
The problem was in the CSS font path which is weird regarding file structure...
@font-face {
font-family: "Gilroy-Bold";
src: url("../fonts/gilroy-bold/Gilroy-Bold.woff2"),
url("../fonts/gilroy-bold/Gilroy-Bold.woff");
}
I tried both url(./)
and url(../../)
but none of it works...
Using local web fonts with webpack
Got a working solution thanks to @omerts in this thread. Solution involved using publicPath. I had been trying to use it as an option in module.exports with the fonts file-loader, not the output.
Updated webpack.config.js:
const webpack = require('webpack');
const PROD = JSON.parse(process.env.PROD_ENV || '0');
const path = require('path');
const PATHS = {
build: path.join(__dirname, './src/public')
};
module.exports = {
entry: './src/app/App.jsx',
output: {
path: PATHS.build,
filename: PROD ? 'bundle.min.js' : 'bundle.js',
publicPath: PATHS.build
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: '/node_modules/',
query: {
presets: ['es2015', 'react', 'stage-1']
}
},
{
test: /\.s?css$/,
loaders: ['style', 'css', 'sass']
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader?name=/fonts/[name].[ext]'
},
{
test: /\.(jpg|png)$/,
loader: 'file-loader?name=/fonts/[name].[ext]'
}
]
},
plugins: PROD ? [
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
compress: {
warnings: false,
drop_console: true
},
mangle: {
except: ['$'],
screw_ie8: true,
keep_fnames: false
}
})
] : []
};
Related Topics
Translate X and Y Percentage Values Based on Elements Height and Width
Two CSS Files Defining Same Class
CSS Cursor Pointer with Svg Image
Is There a CSS Media Query to Detect Windows
Styling Browser-Native Video Controls
CSS Selector for Not a Child of Element Type
How to Select All Elements Whose Id Starts and Ends with Specific Strings
Tint Image Using CSS Without Overlay
How Is "Grid-Template-Rows: Auto Auto 1Fr Auto" Interpreted
Chrome:How to Turn Off User Agent Stylesheet Settings
CSS List Item Width/Height Does Not Work
Less CSS Set Variables in Media Query
Override CSS for HTML5 Form Validation/Required Popup
How to Ensure That Text Is Inside Rounded Div