-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading files from css. #1553
Comments
Have you figured it out? |
I've encountered an analagous issue with Bootstrap's Glyphicons. See http://stackoverflow.com/questions/42228340/fonts-not-loading-after-upgrade-from-webpack-1-to-webpack-2 I'll study your example above as it's more advanced than my own webpack.config code and I am always keen to learn, but I'm wondering why you've closed this. |
Actually I could not find a solution. After 6 hours of work, I could not reach any result. I have not found a complete solution on the internet. I closed the issue thinking "Maybe I'm doing something wrong and I will look like an idiot." Here is what I did: I usually eject app to add additional loaders and resolve src folder as root. First, I closed the quiet mode from I tried many loader options. When I can not reach a result, I try to import one of the images from within JS. When I import it in this way, the image is loaded properly. Interestingly, when I enter the URL of image which is loaded from css, to browser, the image is loading properly. So I gave up on trying after many hours. I still do not know what I did wrong. I can upload code to git if you want. |
Can you reproduce this without ejecting? |
In my case if I just build a production version with pretty much the same config and serve it up directly the fonts load fine. It seems to be webpack-dev-server that's the issue. I'm sitting in a taxi now but can happily put together a minimal example that demonstrates the problem tomorrow. |
No I get urls are loaded correctly from css when I do not eject the app. Now I will eject the app and enable css-loader module. |
It helps me determine how critical the issue is. If it happens before ejecting, it’s a blocker. If it happens after, it’s a problem in how you configure it. We try to help but we aren’t Webpack experts either so you might want to file this directly with WDS or Webpack. |
I'm not sure whether relates to this issue, but I've got a similar problem. |
If you can reproduce this in a project without ejecting, please provide this project and exact instructions to reproduce. |
Yes. This issue can be reproduced without ejecting. What I did was:
I used Lerna to organize these local modules.
And the
|
I tried to move one of my projects to create-react-app structure and I couldn't make this work. Even if I eject the project, I haven't found a way to load fonts or images from within SCSS files. I tried using file or url loaders with no luck and it was really frustrating.
I added these loaders into webpack.config.dev.js. No luck.
|
@giridharangm Please provide a full project. I don't understand what you are trying to do, or what problem you have, from your comment alone. As documented in the User Guide, you need to prepend any file URLs with
If it’s not clear enough, please send a pull request to improve the documentation. |
Yes, I tried using |
You said fonts are in the src directory, but your styles are in a subfolder. So |
So, to be clear, it works exactly like imports in JS. You need to supply a path relative from the folder where your CSS lives. |
If you look at the error message you posted, it says which directory it is looking in, and which path it is trying to find. You can see that it doesn't match your folder location. Use that information to fix the path, and it will work. 😉 |
@gaearon and you were right ! Sorry for my silly question. A matter of correct paths. Thanks for your time. |
@alduro No worries! I’m glad you got it working 👍 I’m going to close this issue because the problem @gkhno reported seems to only affect configuration tweaked after ejecting. So this is not really a problem of CRA itself, but rather a Webpack usage question. We’re not really in the best position to answer it, and I suggest engaging with Webpack community for help. Unfortunately we can’t provide support for every possible Webpack configuration in this issue tracker. The problem @giridharangm described further doesn’t seem related to the original issue to me. It looks more like a problem with Lerna setup and some assumptions Create React App might be making about paths. I’m happy to look at it but we’ll need a separate issue and a published project reproducing this. |
@gaearon may be you're right. I was wondering about lerna configuration too. My problem isn't about loading files using
Sorry if I wasn't clear about the issue earlier. I've created a sample repo to reproduce. Please have a look. |
Can you please create a new issue? It’s easier to keep track this way. |
Can you reproduce the problem with latest npm?
Yes.
Description
Font Awesome is installed with npm. I am importing the it from
scss
:@import '~font-awesome/css/font-awesome.min.css';
In react-scripts 0.8.2 this was working without a problem. Fonts were loading correctly.
When I check the loaded css, I see that
url()
of font face replaced correctly with/static/media...
Note: this also happens when importing font with
@font-face
.NOTE2: also images cannot bi loaded from scss files.
NOTE3: importing from css or scss files does not work. Files emitted on webpack but I cannot see them from chrome devtool. But importing from JS works.
Expected behavior
Fonts and images which is defined in
css
orscss
should load from browser correctly.Actual behavior
Fonts and images are not loading from browser on render. For normal fonts (not icon fonts) I imported from google and working fine. But when I try to import from css as local file, It is not loading on render. If I enter the url of the media to browser, I can reach it.
Any import or
url()
call does not get the files.Environment
npm ls react-scripts
(if you haven’t ejected): Ejectednode -v
: v6.9.2npm -v
: 4.2.0Operating system: Windows 10
Browser and version: Chrome 56
Reproducible Demo
Freshly installed and ejected react-scripts:
package.json
config/webpack.config.dev.js
index.js
(this is where I import the style file which contains font-awesome import.)index.scss
In some component:
The text was updated successfully, but these errors were encountered: