App works perfectly when running locally using parcel src/index.html
, however after creating a production bundle by running parcel build src/index.html
and attempting to serve the static assets using vscode live serve or serve the app is being served with missing CSS and JavaScript files. The same thing happens when the app is served via github pages. Interestingly enough, http-serve is able to serve the app in its entirety. The repository containing whole source code can be found here
App is being served including CSS and JavaScript files.
App is served without CSS and JavaScript assets
Errors when accessing page served by github
src.184de31a.css:1 Failed to load resource: the server responded with a status of 404 ()
src.152c138c.js:1 Failed to load resource: the server responded with a status of 404 ()
src.184de31a.css:1 Failed to load resource: the server responded with a status of 404 ()
Changing the mime types of CSS and JavaScript assets
The repository containing whole source code can be found here
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0
| Node | 10.7.0
| npm/Yarn | 6.5.0
| Operating System | Linux
Hello @mytee306, you can set the option --public-url
. To make github pages work for instance, you have two options:
parcel build src/index.html --public-url='./'
.
It would then serve the assets from https://mytee306.github.io/nns/
as opposed to https://mytee306.github.io
.
Alternatively
parcel build src/index.html --public-url='/nns'
should work too - same logic.
Someone correct me if I'm wrong, but the reason it doesn't work is that by default parcel expects that the bundle is in the server's top-most / root directory. In github pages case, they are nested in nns/
. So if you run serve / http-server
in dist/
it should work. If you run them one folder above, it won't, unless you set --public-url
@lustoykov Works like a charm, thank you so much!
Shouldn't parcel change default then? Looks like a bug.
@mihailik I was wondering the same, would be nice to hear the opinion of a contributor. As far as I can tell --public-url './'
does not bring unwanted side effects.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
Most helpful comment
Hello @mytee306, you can set the option
--public-url
. To make github pages work for instance, you have two options:parcel build src/index.html --public-url='./'
.It would then serve the assets from
https://mytee306.github.io/nns/
as opposed tohttps://mytee306.github.io
.Alternatively
parcel build src/index.html --public-url='/nns'
should work too - same logic.Someone correct me if I'm wrong, but the reason it doesn't work is that by default parcel expects that the bundle is in the server's top-most / root directory. In github pages case, they are nested in
nns/
. So if you runserve / http-server
indist/
it should work. If you run them one folder above, it won't, unless you set--public-url