-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Wrong relative path to URL assets when bundle lives in subdirectory #1801
Comments
I think your solution is the correct one in this case. The result should always have the publicUrl as a prefix |
Issues that look related: |
What is the status of this issue? I would like to switch from webpack to parcel but this is really big problem for me. Is there any workaround for the time before any fix? |
Hi I am currently having the same problem here and I would like to know when the next version with this fix is released. |
I would really like to have this feature as well. One of the key benefits of parcel is that it generates unique file paths for assets. This prevents version mismatches and allows aggressive caching. However it is very difficult to set caching headers for these assets because there is no easy pattern to select them with. If there was a directory for non-entrypoints then it would be easy to set cache forever headers on anything in that directory. The only workaround I can think of right now is setting |
🐛 Bug Report
When two bundles in different directories with the same file name are generated, the directory structure is reflected in the output. This causes an issue with URL dependencies because their paths are relative to the current directory.
🎛 Configuration
Given the following directory structure:
With the contents of
assets/a/bundle.css
being:And the following Parcel command:
The following directory tree is correctly generated:
So far so good. However...
🤔 Expected Behavior
I would expect the contents of
dist/a/bundle.css
to be either:Or:
😯 Current Behavior
The contents of
dist/a/bundle.css
is currently:Which means the browser will request
/a/foo.png
, but the file is located at the web root – not in the "a" directory.💁 Possible Solution
I'm really not familiar enough with Parcel to make an educated recommendation as to how is should be fixed, but I'm guessing the best way to fix the issue is by somehow making calculating the relative path to the URL asset from the bundle. So that (using the example code above), the output URL would be
url(../foo.[md5].png)
Another possible solution is to join the URL with the publicURL option. This could be achieved by modifying the
Asset#addURLDependency()
method's return value, like so:This method seems to work, but as said before, I'm not familiar enough with Parcel to know if it's a viable solution. It does require modifying some tests, which indicates it could be a breaking change. Would love some feedback.
I have made a commit and will definitely create a PR if the solution is approved.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: