I'm struggling with adding Font Awesome to my webpack project.
I use file-loader
to get webfont files to static/webfonts/
. Then I use mini-css-extract-plugin
to extract css from bundle to static/css/
. It results in wrong URLs such as:
static/css/static/webfonts/fa-solid-900.9451d5fe.woff2
Only way to make it work is outputting css to root (doing the same with file-loader doesn't work). Any ideas what I'm doing wrong?
Here is my webpack.config.js
:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (env, options) => {
const isDev = options.mode === 'development';
return {
mode: isDev ? 'development' : 'production',
entry: {
app: './src/js/index.js'
},
output: {
filename: 'static/js/[name].[contenthash:8].bundle.js',
chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './public/index.html'
}),
new MiniCssExtractPlugin({
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
})
],
module: {
rules: [
{
test: /\.css$/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
]
},
{
test: /\.(eot|woff|woff2|ttf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash:8].[ext]',
outputPath: 'static/webfonts'
}
}
]
}
]
}
};
};