parcel: Wrong path for css and js file on build
đ bug report
When using build (or start) the path to the .js and .css file in the index.html in the dist folder donât make much sense to me.
For example, the .js file is included like that:
<script src="/dist/7d97f2dde78701558fc2691e34c9052b.js"></script>
shouldnât the path be without the dist like this:
<script src="/7d97f2dde78701558fc2691e34c9052b.js"></script>
makes it much easier to serve the files.
| Software | Version(s) |
|---|---|
| Parcel | v1.2.0 |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 27 (10 by maintainers)
I suggest the same thing @TomasHubelbauer has said.
I couldnât make it work until I set the command from
parcel build src/index.html -d publictoparcel build src/index.html -d public --public-url ./This is due to the fact that it feels natural that ./ or . is set as default, even if itâs not.
I have a similar concern here. My source folder structure is pretty simple:
When I run
parcel src/index.htmlfrom the root directory, Parcel creates adistfolder alongsidesrcwith a modifiedindex.htmlfile that references my CSS and JS files using the/dist/<file name>.jsas @j-o-d-o described.Problem 1: My
index.htmlfile is inside thedistfolder (effectively at the root of thedistdirectory) so, to begin with, requiring it to look inside/distby default isnât helpful; and Problem 2: Parcel seems to completely ignore the asset folder structure when it compiles thedistversion and I canât work out how to change the default behaviour to respect it.I tried running
parcel --out-dir src/index.htmland that just created aindex.htmldirectory and replaced/dist/with/index.html/in my paths.Desired behaviour
When I run
parcel index.html(or perhapsparcel src/index.html), Iâd expect Parcel to create adistfolder alongside my source files with CSS and JS paths that correctly load those assets when I view the newly compiled/createdindex.htmlin thedistfolder.What am I missing here?
Navigating through 100 issues and I donât see anything resolved. It doesnât make sense that all images, css and js are put in root directory.
This should definitely be changed so that it behaves as though the
--public-url .option was set by default. One should be able to just runparcel build index.html, move the files indistto a file server and have everything work. The current behavior of theindex.htmlfile indistloading assets fromdistas if it was in the super directory makes no sense. I hope #557 can be merged so the default behavior is user friendly.@mohsen1 Doesnât Parcel already have that?
Just another reminder that the
--public-urlhas to be set to./manually to enable dropping the production folder anywhere. This needs to be standard behaviour and has not been addressed yet. Can we have an update on this?Okay, I have another problem regarding this issue. If I want to use static images I would do something like this:
When using
>> parcel src/index.htmlthe path to the image is wrong. To resolve this I have to change the path:<img src={"dist/" + testImage} />. But Then, when I build my project with ââpublic-dir /â flag, the image has the wrong path in the build projectâŚHow can I resolve that?
Maybe we should add an issue to the
/websiterepo to get the docs fixedIf that works than this is probably bad documentation not a parcel bug
There needs to be a âpublic pathâ option. It would be useful when assets are uploaded to a CDN or served under a special path in production.
I agree that
--public-url ./seems like it should be a default. My simple CSS and JS references in an HTML file does not work until I set this.Ah, thanks @Giorat - I was just running into this exact problem, and your comment still didnât make sense until I saw for myself:
[16:33:43] me ~/Code/devops-dashboard $ node_modules/parcel-bundler/bin/cli.js build src/public/segments.html --out-dir src/public/dist --public-url ./dist/vs[16:38:16] me ~/Code/devops-dashboard $ node_modules/parcel-bundler/bin/cli.js build src/public/segments.html --out-dir src/public/dist --public-url ./This does feel strange to me. I agree that it feels natural for ./ or . to be set as default.
use the cli flag
--out-dirto change this behaviourRead this https://parceljs.org/production.html the default dir is
distOkay turns out #557 was closed in favor of a different PR which doesnât deliver this, which is most unfortunate and there is a conversation lockdown with a message to open up a new issue to discuss this. @davidnagli could this issue be reopened to track this request to have the default be sensible in terms of static file serving?
@j-o-d-o this is another issue that should need a seperate bugreport
Sorry for closing this, u are correct this would be a better approach (in some cases) iâm not sure but think there is already an issue concerning this