Can't load font files using custom webpack
See original GitHub issueCant load font files using custom webpack.
Font files are stored at: src/assets/fonts/[.eot, .ttf, .woff, .woff2]
custom webpack (even using the comment out webpack config below doesnt help):
config.module.rules.push({
test: /\.(eot|ttf|woff|otf|woff2)$/,
include: [path.resolve(__dirname, '../src')],
use: [
'file-loader',
],
// use: {
// loader: 'file-loader?name=/fonts/[name].[ext]',
// options: {
// name: 'assets/fonts/[name].[ext]',
// },
// },
});
Storybook version:
"@storybook/addon-actions": "^5.0.11",
"@storybook/addon-info": "^5.0.11",
"@storybook/addon-links": "^5.0.11",
"@storybook/addon-storysource": "^5.0.11",
"@storybook/addons": "^5.0.11",
"@storybook/react": "^5.0.11",
Please advise.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Webpack can't load fonts (ttf)
Webpack requires a font loader to load font files present in your project. you are using a file loader to load fonts. Change...
Read more >Loading Fonts with webpack
The first thing we have to do is install an external webpack loader called file-loader. File-loader will allow us to import file-based assets ......
Read more >How to use Fonts with Webpack 5 - Setup Tutorial
In this tutorial, you will learn how to set up a local font with Webpack. We will use Open Sans, but you can...
Read more >file-loader - webpack - JS.ORG
The file-loader resolves import / require() on a file into a url and emits the file into the output directory. Getting Started. To...
Read more >Load images and fonts with Webpack file loader like a pro
Webpack file -loader is a loader used mainly for supporting images such as SVG and PNG, and fonts in your webpack project. If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just got it to work by using CopyWebpackPlugin instead of the file loader.
Our usecase is this: multiple apps in the same repo (monorepo). Among them, one is a library of common UI components, and it also has storybook. The fonts are located in a different app client/. I wanted to import the fonts from client app inside common-ui to be used by storybook.
Inside storybook’s
webpack.config.js
I added:And then, inside preview-head.html I added:
And it woooorks 🎉
I am using sass files and also have @font-face imports in them.
Here is the webpack.config.js that worked for me: