-
-
Notifications
You must be signed in to change notification settings - Fork 389
-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Asset links broken when extracting CSS and assets to different folders #691
Comments
Please do not ignore how we can reproduce, sorry won't fix without it, I don't know your |
Hi, I didn't "ignore" the option, I just couldn't think of anything to say there that wasn't already in the other sections. I'll add the info you asked. I'm building normally - I don't know if the issue happens when serving via dev-server, as (per the docs) I don't use CSS extraction in that case. |
@AndyHall So please provide full configuration and part of code, or better minimum reproducible test repo, I am really want to help, but many issues without good examples and I can't help |
Feel free to ping me when it will be ready |
@alexander-akait Sorry, I don't know what you're asking for. The config I posted is already as minimal as I can make it, and it took a fair bit of effort. Are you saying you want the full config I'm using, including everything that isn't related to this issue? |
@AndyHall I can't reproduce problem with your configuration, so yes, I need fully, you can just create simple reproducible test repo and include part of configuration where the problem reproduced |
Why you have |
Wouldn't that mean the generated resources will all have hard paths relative to server root? I'm using
For a closed issue? |
It was closed, because you don't provide enough information to help, if we will keep opened all issues where developers doesn't provide enough formation, here will be trash and will be hard for developers found real problem(s), I will help and/or reopen it if you provide steps to reproduce |
I'm trying in good faith to report an issue. There's no call to be referring to it as trash or not a real problem. Here is a minimal repro. Config, code, and steps to reproduce are same as posted previously. |
I understand you, but try to understand me too, I got very many issues every day and when developer provide only part of code, it requires me to spend efforts on recreating configuration and code to reproduce the problem and most of times not problems (from my experience it is 99% of problems), so other developers won't get help or fixes/features because I will spend most of the time trying to reproduce the problem |
I understand how maintaining works. But if policy for this module is to close any issue without a repo, just say that in the readme or the issue template. |
Yep, I will update |
I need think about it more, now you can use |
Setting |
@AndyHall Yes, in ideal we should https://github.com/webpack/webpack/blob/f9a2c275855027e828983e731ce98189fb7b6d81/lib/util/identifier.js#L311, but we have url only after building, don't have good idea how we can fix it, I need think about it... Note for me: |
@alexander-akait Take your time, there's no rush. I'm already working around the issue myself; I only posted this issue for others who might encounter it. |
I believe I am having the same issue... I am including However, because the component that's including the less is getting included from a file in |
It seems that we should be able to compute a relative path in |
If somebody have solutions right now, feel free to send a PR |
Working on it. I must say it's hard to get ones head around I have something that works for me... I'm wondering if it will do the trick for everyone. MiniCSSExtractPlugin currently supports the My solution sets In const publicPath = path.relative(path.dirname(chunk.name), "");
content = content.replace(/\/__MINI_CSS_EXTRACT_PLUGIN__/g, publicPath); So now the "auto" mode means that we compute a relative path from our output file to the I'm going to prepare a PR. I'd love some feedback if this approach seems suitable. |
I've also published a test module that we're using internally at https://npmjs.com/@cactuslab/mini-css-extract-plugin that might be the easiest way to test if this resolves your issue @AndyHall |
@karlvr I tried your plugin in my reproducing repo, but webpack's output didn't change at all. Was I supposed to do something besides swapping the main plugin for yours? |
@AndyHall do you have |
@karlvr I'm building the minimal-reproduction repo linked up-thread. Versions and settings are in the repo. Edit: in that repo I swapped the plugin module to yours, and tried building with and without the |
@AndyHall thanks Andy... I have reproduced the fault in your minimal repo. I made some assumptions about the chunk name and that it would reflect where the output was going. It does in my case as I use a relative filename for my outputs... So, all we need to know is where we're planning to write the file that we're outputting. Is that possible? |
@AndyHall OK, please upgrade to 1.3.10 of @cactuslab/mini-css-extract-plugin. This now looks at the output filename template to work out any additional relative paths to consider. In your case, that is In order to make it work with your repo I removed the I am really straying into an area of interacting with the webpack API that I'm not at all familiar with. I hope there's a function to render a filename template given a chunk... I've just regexed the name into the template in case the name contains path components! |
@karlvr Is removing I tried the steps you suggested and they fix the CSS link, but per the original post, (I could be missing something, I don't know anything about webpack internals and wasn't able to follow what your fix is doing.) |
@AndyHall Good question. Removing What is the intended meaning of setting Anyway… it would be possible to activate this patch on any relative Super easy to change the patch to this way of thinking. Is it too much or flawed @alexander-akait? I'm starting to think it's actually essential. |
You are right here, in long term we should avoid using |
@alexander-akait Perhaps a good first step is to take |
Hi, just to clarify here I'm using |
|
@AndyHall removing @AndyHall you mention that removing Also, please upgrade to |
Hi @karlvr , regarding "removing publicPath will achieve what you want to achieve", I don't know what you mean. Having However with that said, using the |
Yep, it is good fix, need couple test and we can merge it |
Yes, that's literally absolutely correct, however I think the intention of the two is the same. I think webpack 5 just made it explicit. The default was empty; the default is now auto. An empty publicPath is broken for CSS when the CSS is located out of the root. But people expect it to work as I think they want it to mean "use relative paths and make it work", which I think is synonymous with auto. That's why I'm curious what breaks by adopting publicPath auto (or removing publicPath and thus using the default value of auto). My expectation is that everything just works, and where it doesn't there lie more bugs to fix! |
Anyway, can you add couple tests for your PR? |
This worked for me!! Thanks a lot 🇧🇷 @karlvr When I added |
@karlvr would you be able to resolve the linter errors so your PR can be merged? Thanks in advance! |
I think it helps you,dynamic publicpath |
Fixed by #772, if you use before |
What is "v2" here? Do you mean a future release? |
WIP on release right now |
Done https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v2.0.0, the next goal first class HMR supporting, including |
Fixed mine using Webpack 5 Resource assets instead of using file-loader.
|
Expected Behavior
I'm using
MiniCssExtractPlugin
to extract CSS, and with default settings everything works fine. However I want to export the CSS to its own folder, separate from image assets, like this:Per the docs, I'm doing this by passing a
filename
option to the plugin with the desired folder name.Actual Behavior
When I pass in an option like:
filename: 'styles/[name].css
, the CSS file itself gets exported to the correct directory. However,url(..)
asset links inside the CSS aren't adjusted, and wind up broken as a result.Specifically,
styles/bundle.css
winds up containing references likeurl(assets/image.png)
, causing the browser to requeststyles/assets/image.png
.Code
The relevant code snippets look like this:
After running webpack, the CSS winds up with broken asset links:
How Do We Reproduce?
By building a project with configuration as described above (in production mode).
Is there some setting or workaround supporting this use case?
Thanks!
The text was updated successfully, but these errors were encountered: