Here is my regex for fonts and svg image loader and they are in conflict, since they both target *.svg file. How to solve it?
{test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file?name=/Presentation/_dist/fonts/Interstate/[name].[ext]'},
{test:/\.(png|jpg|gif|svg)$/, loader: 'url?limit=10000&name=/Presentation/_dist/images/[name].[ext]'}
A custom webpack config for Storybook needs to be set up to specify @svgr/webpack as a webpack loader for .svg assets. The @svgr/webpack loader rule needs to occur before that other loaders like the file-loader rule so that @svgr/webpack takes precedence.
The @svgr/webpack loader rule needs to occur before that other loaders like the file-loader rule so that @svgr/webpack takes precedence. Place the @svgr/webpack loader before existing webpack asset loaders using Array.prototype.unshift ().
To summarize, to avoid any font related errors with webpack, you need to download file-loader, integrate it within your webpack config, and import whatever fonts you wish to use into your CSS or SCSS files.
webpack file loader is a loader used mainly for supporting images such as SVG and PNG, and fonts in your webpack project. There are different configurations for webpack 4 and webpack 5.
You can use exclude
and include
to eliminate the problem.
Something like:
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
include: [
path.resolve(__dirname, "MY-FONTS-FOLDER")
//, Any other svg font path
],
loader: 'file?name=/Presentation/_dist/fonts/Interstate/[name].[ext]'
},
{
test:/\.(png|jpg|gif|svg)$/,
exclude: [
path.resolve(__dirname, "MY-FONTS-FOLDER")
//, Any other svg font path
],
loader: 'url?limit=10000&name=/Presentation/_dist/images/[name].[ext]'
}
Note:
MY-FONTS-FOLDER
with the actual fonts folder path.font.svg
for the file-loader and .svg
BUT NOT font.svg
(maybe negative lookahead) for url-loader.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With