-
-
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
Is there a way to build html with relative assets url? #206
Comments
Yes, use --public-url when building: |
Built files written in Example: test.html:
test.js:
Command, using version
Now
The file |
|
Use --public-url option to ensure assets are linked like "app.7c88748f.js" instead of "/app.7c88748f.js" The previous link behavior was causing 404 errors for the assets when hosted on GitHub Pages See parcel-bundler/parcel#206 parcel-bundler/website#30
For anyone that just really wants to see a './' before the url, what I did was to change the build command (on Mac) to: I found no other way to force the '.' in the url. |
Relative urls are necessary if one is using parcel to build for a subdomain. This is a necessary feature. @albinotonnina |
Wouldn't it also be saver in general to have I can imagine other scenarios were relative paths are not necessary or need to be altered are way less common than this one. |
Note that if you are using something like Is there any way to have the asset paths be relative to index.html, si it will work wherever you place the index file? |
maybe |
I did it! I managed to make a production build that has
I wrote a more detailed blog post here. Note, this feels like a very hacky solution, but I did not find any other way to make a fully build application be completely path independent and use only relative paths. |
I would recommend deleting your |
Why it's closed? I still don't see a way to produce |
@pawelkedra |
@mischnic it doesn't, it produces |
Well, |
@mischnic it matters if your site is not deployed at the root of the domain, e.g. |
I agree with @pawelkedra. Having an option to output files that use |
Any update on this? Why is it closed? |
|
Any updates? |
@EmmaGoodliffe I'm trying, but my index.html points to {public-url}/src...js, but the actual file is not there :c |
@exsesx Sorry, I'm not quite sure what you are trying to do 🤔. What is the path in your source index.html and what do you want to change it to? |
Thanks to @ErikSom
|
I did
And now my file paths are relative (the |
I think using |
Are any updates on it?
|
Thanks, using |
It does not work for me neither I'm using Things I tried
the repo at: https://github.com/codingedgar/macos-multi-select workaroundI manually changed the #### Edit |
Would recommend to do something like this: |
thankss
|
I feel like there's a smarter way to do this. Parcel is all about being minimal-config right? The reason I'm here was trying to build a basic html page (I know, not main use-case, but still, hear me out). When I link the script in my HTML, I already 'chose' if I want that href to be relative to the file, the domain root etc. Why not have parcel analyse & repsect that? |
Can anyone help me out I
What's the equivalent windows command for |
Is there an official solution to this? Been stuck on it for days. |
If you know the subdomain the resources are on, you can use that as the - "build:prod": "npx parcel build --public-url ./ index.html"
+ "build:prod": "npx parcel build --public-url /My-Subdomain/ index.html" 'test.hash.js' will now resolve to '/My-Subdomain/test.hash.js' as is expected. |
Thanks! This helped me out. |
Why is this still not fixed? I have a repo using Parcel and I also have a |
For the linux people: |
Since ./ does not result in relative imports, it's not possible to move the dist output into a sub directory when including a service worker. This can't be fixed with the Any official statement on this? |
Could we please reopen this issue, as the sed workaround is not applicable for using with service workers |
## Motivation - Following vega/editor#1420, #9276 stopped working - This updates the build command for compatibility with parcel. ## Changes - Updates stale comments - Don't mention vite, try to stick to the yarn build command (with 1 parcel specific flag parcel-bundler/parcel#206 (comment) ) ## Testing - Check if deploy preview link loads correctly ( [src](https://cameron-yick-fix-deploy-prev.vega-lite.pages.dev/#/url/vega-lite/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykBaADZ04JAKyUAVhDYA7EABoQAEzjQATjRyZ289AEEABBBoIcguIaZJ1h2DcyGA7nRiHETOMtXLDypJhUiioBKKigxEiCDGpoANqgYSD6wUxoAEwAHAC+ColoIABCqWhiYrn56ADCJagALADMFSBJACK1AJwAjM1JAKK1mT15LQUAYrViTSNJAOK1XR29BQASgwDsy+gAkpPp2QC6uSDI6gDWBdbqwXCyUGzKNLJkaKAAHq8gAGY0cILKBRQSkwAE8cHACrI2AgnlFgkg3jQIJ9BEhPIJ9M8LGgAAzZY4gz4-P4A9BpYFgiHoACODCQsh0gR0pBA+OyQA) )
Having relative paths is a requirement for IPFS 1 2 3 4 and the above workarounds are hacks, at best. Being able to generate relative asset URLs and/or prepend a path is a requirement. For another workaround, one that may be converted into a Parcel plugin (or ideally build flag), I found this: https://github.com/tmcw/make-relative |
Choose one: is this a 🐛 bug report or 🙋 feature request?
🙋 feature request
🤔 Expected Behavior
When exec
parcel build docs/index.html
, the generated html should have relative assets url, such as:😯 Current Behavior
The url is an absolute path:
💁 Possible Solution
Is there a way to build html with relative assets url? Maybe some configuration?
🔦 Context
A common practice is to only host the dist (or public) dir using a static server. But with absolute path, it cannot find the assets resource.
The text was updated successfully, but these errors were encountered: