-
Notifications
You must be signed in to change notification settings - Fork 511
relative urls to images in css point to the wrong place #27
Comments
That's a bug. The ExtractTextPlugin need to handle a filename like |
Thanks for the response! So just to clarify the behavior of the bug, webpack will correctly take into account the output path of images, but will fail to modify each path relative to the output css file. So, for instance, when I tried to manually make the output of the files relative to the css file, the css file would be changed from Let me know if there's anything I can do to help! I'm going to be poking around the webpack architecture to see if I can solve this bug myself but it is low priority given that I've found a decent workaround. |
I added a (not published yet) |
I think I might be having a similar issue. I'm not sure if there's a way for the plugin to generate relative I am currently, only able to load assets via In the css-loader I define the app root path which allows me to reference the images with (app source) root relative paths. They are picked up by the file-loader, renamed and written to the root of the output dir. With just this setting alone, regardless what directory a CSS file may be in, there is no file path for any values passed to E.g. A file referenced in SASS as: Is referenced in CSS as: I am assuming that this is because there is no awareness of the locations the various CSS files are being extracted to when these paths are being generated? To overcome this, in the It would be nice to have the option of using relative paths to make the output files more portable. I thought I'd inquire as to whether there is a way to achieve this with existing configurations before attempting to create a post processing step. What might be helpful is way to access files being processed before they are output, manipulate them and pass them though. I'm not sure if there is already a plugin for this or not. I've included the relevant portions of my config in case it helps explain.
Thanks! |
That's actually a problem. It occurs when you put your css files into different folders. I cannot fix it easily because the design is like this: when css code is extract from modules the output file is not yet known... |
@sokra Ok, thanks for letting me know! |
@sokra is there any progress/roadmap for this ? relative url are must for us and I dont know how to overcome this issue... we've recently switched our code base to work with webpack. Also Is there any alternative in webpack to scaffold css from sass with relative urls ? |
I think there is nothing do in this issue.
I was wrong. There is no problem here, just use |
Still met the same problem ... 😥, and I really do not prefer to use flatten folder structure in my dist folder. (there're several output css files, and it would seem to messy to put them all in one folder) and here's my dist folder output: and here's my image loader config: Hence in bg.css output file, the background-image url path ( However, if I changed the code in my sass bg.scss file output: then the image would be rendered in my dist/images/bg.jpg, but in my dist/css/bg.css file, background-image url path ((localhost:8080/css/images/bg.jpg)), hence the image was not found. in my new ExtractPlugin config, I used the Any Help? @sokra |
@woohling Same issue. |
@woohling Because Regarding you second case, you should fix it via overriding the Please refer to this commit I did for |
@changLiuUNSW I set the publicPath option to |
@woohling you should look this ExtractTextPlugin.extract([notExtractLoader], loader, [options]) Creates an extracting loader from an existing loader.
webpack: 2: ExtractTextPlugin.extract(options: loader | object) Creates an extracting loader from an existing loader. Supports loaders of type
|
@liuqipeng417 setting the publicPath didn't work for me.. 😥, the image-url in sass file still relative to |
Intrigued to find out if anyone managed to solve this issue? Having the same issue. I ideally want to house my .css file inside a css/ dir in my dist output dir. |
@sami616 : The below solution worked for me. You can try and confirm |
we still struggling, I have the same issue , extract-text-webpack-plugin, |
@hamodey85 Suggest extract all static files in a same dir without subdirs.
|
@huoxy my build file will be messy , |
the problem was with file-loader setting, I just fixed it by fixing the publicPath: publicPath: "../" |
If you need to modify the url's without changing publicpath etc, you can use 'string-replace-loader' as shown below. (Took me weeks to work this out)
|
@jakenuts your solution works. thank you! |
I'm trying to compile a legacy css file. In this legacy file, there are relative url like `background-image: url(../images/cta-newsletter.png), which get resolved according to the location of the stylesheet. Unfortunately, the extract-text-plugin (or maybe one of the loaders?) will remove this relative url.
I use the url-loader for images like this:
and the ExtractTextPlugin is added to the plugins array like this:
so that compiled images and css files go into images and css respectively in the build dir, which mirrors what the src dir looks like.
Am I doing something wrong or crazy? Is there a way to have this plugin keep track of relative urls? Lemme know if this is unclear and I'll explain further.
Thank you!
Brian
The text was updated successfully, but these errors were encountered: