css-loader: css-loader parse fail on @font-face
I get this error when webpack tries to run:
ERROR in ./bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
Module parse failed:
./bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
@ ./~/css-loader?importLoaders=1!./bower_components/bootstrap/dist/css/bootstrap.css 2:4480-4532 2:4551-4603
Here’s my configuration
module: {
loaders: [
// Pass *.jsx files through jsx-loader transform
{ test: /\.js$/, loaders: ['react-hot','jsx?harmony'] },
{ test: /\.css$/, loader: "style-loader!css-loader?importLoaders=1" }
]
}
Is it something in my config that’s wrong or missing something?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 31
- Comments: 48
I needed to add url-loader to my config
None of this works for me
Thanks for the answer @mattybow, it seems better to add a suffix regex to fit more general cases, the following configuration works for me: { test: /.(png|woff(2)?|eot|ttf|svg)(?[a-z0-9=.]+)?$/, loader: ‘url-loader?limit=100000’ }
Кто пояснит, в какой именно файл это вписать? Какой именно конфиг??
This code worked for me with webpack2:
I’m using https://icomoon.io/app/ , my css looks like:
Hope it helps.
None of the solutions worked for me until I changed the paths to absolute Ex.:
It’d better be
to cover caching specific versions
👍
You can find the full solution here webpack-bootstrap
file-loader
grabs the file and handle its writing on build (you could specify saved path/name.extension, and other nice features it has).url-loader
tries to load up file data inline by usingblob
style url loading, but it would do it only if a file size is under thelimit
specified, otherwise it will fallback and usefile-loader
instead.URL loader is indicated to be used on
images
and other small resources you could have.Loaders order definition is important because they pipe the content over them. Here are some examples so you can understand how it works under the hood:
file-loader example
Just remeber to install file-loader and url-loader before changing your webpack config. Using :
npm install --save file-loader url-loader
For people from the future, I went with a different solution. I used
raw-loader
:Then imported fonts where I wanted them with
copy-webpack-plugin
:This gives me some extra control too so we avoid importing fonts unintentionally from other plugins, etc.
what if you are not wanting to bundle fonts at all? I originally had my pcss being parsed by postcss-cli and output to the same dir as webpacks build.
In
webpack.config.js
in the section withrules
. This is what works for me (slightly different from the proposed solution):You also need to install
url-loader
andfile-loader
forwebpack
with this command (if usingnpm
):@cusspvz:
From the package.json
We ended up getting the fonts to load using
file-loader
in lieu ofurl-loader
. To be completely honest, I’m unsure of the nuances between the two loaders. I also ended up switching the order in which the loaders were applied, which I think ultimately did the trick.When I was experiencing trouble, Webpack was processing the font files before processing the Sass files. I rearranged this so that the order went:
Either way, the process was a little bit similar to shooting in the dark, but it’s working now.
Try to install modules:
yarn add style-loader
yarn add css-loader
yarn add url-loader
Then in webpack.config.js add:
And make import of CSS file (For example i have):
require ('react-notifications/dist/react-notifications.css');
thanks @TonyWang031
before :
it worked! after apply:
I add the rule by zyxneo into webpack.config.js and redo
npm run dev
It’s fixed! Thank!Slight improvement to @TonyWang031 suggestion as it gives invalid regex
{test: /\.(jpe?g|png|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/, loader: 'url-loader?limit=100000'}
@mbeauchamp7 It worked because the
~
acts as a module indicator forcss-loader
, meaning that it should load the file over webpack instead of css.Hi, I also have some questions when I
import "amazeui/less/amazeui.less"
.In addition, Please click here about
amazeui
But when I
import "amazeui/dist/css/amazeui.min.css"
questions don’t exist.I think in less file use
font
so it have these questions.Can you help me?
Thanks