Webpack "Module not found: Error: Can't resolve '../webfonts/fa-solid-900.eot' "
It works !!!
webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const BabelMinifyPlugin = require('babel-minify-webpack-plugin');
module.exports = {
optimization: {
minimizer: [new OptimizeCSSAssetsPlugin({})],
},
entry: path.resolve(__dirname + '/public/src/js/adminMain.js'),
output: {
path: path.resolve(__dirname + '/public/dist/'),
filename: 'adminBundle.js'
},
devtool: 'source-map',
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [{
loader: MiniCssExtractPlugin.loader
}, {
loader: "css-loader",
},
{
loader: "postcss-loader",
options: {
sourceMap: true
},
},
{
loader: "sass-loader",
options: {
sourceMap: true
},
options: {
implementation: require("sass")
}
}
]
},
{
test: /\.(ttf|eot|svg|gif|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{
loader: 'file-loader',
}]
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "adminBundle.css"
}),
]
};
variables.scss
$fa-font-path: "../../webfonts" !default;
...
solid.scss
/*!
* Font Awesome Free 5.9.0 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
*/
@font-face {
font-family: 'Font Awesome 5 Free';
font-style: normal;
font-weight: 900;
src: url('#{$fa-font-path}/fa-solid-900.eot');
src: url('#{$fa-font-path}/fa-solid-900.eot?#iefix') format('embedded-opentype'),
url('#{$fa-font-path}/fa-solid-900.woff2') format('woff2'),
url('#{$fa-font-path}/fa-solid-900.woff') format('woff'),
url('#{$fa-font-path}/fa-solid-900.ttf') format('truetype'),
url('#{$fa-font-path}/fa-solid-900.svg#fontawesome') format('svg');
}
.fa,
.fas {
font-family: 'Font Awesome 5 Free';
font-weight: 900;
}
admin.scss
// Variables
@import "./variables/admin.scss";
@import "./fontawesome.min.css";
@import "./solid.scss";
.....
Just needed to do some changes in scss files and now it works. {$fa-font-path}
is the key. Why just cant be anything in webdev easy.
In my case the error was:
Error: Can't resolve '@fortawesome/fontawesome-free/webfonts/fa-solid-900.svg#fontawesome
And I fixed it, adding this to my index.scss
$fa-font-path: '~@fortawesome/fontawesome-free/webfonts';
@import '@fortawesome/fontawesome-free/scss/fontawesome';
@import '@fortawesome/fontawesome-free/scss/solid';
@import '@fortawesome/fontawesome-free/scss/regular';
@import '@fortawesome/fontawesome-free/scss/brands';
@import '@fortawesome/fontawesome-free/scss/v4-shims';
note the "~" in $fa-font-path
and this to my webpack.config
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
},