parcel dev server will serve index.html when `--public-url` is set to `./` (dev server will serve index.html to anything unrecognized)

Created on 13 May 2018  路  8Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

As title. I have used --public-url ./ as a temporary workaround within VSCode's sourcemap behavior documented here. This will made asset linked within compiled html from <script src="/js.8e7f6a41.js"> to <script src="js.8e7f6a41.js">. Without the slash the dev server will consider this unknown path and serve index.html. By using other dev server solution like http-server to serve dist will not exhibit such problem.

I believe this behavior is more confusing than helpful to most users.

馃 Expected Behavior

Have dev server act more similarly to regular http server than automatically try to 'correct' unknown path

馃槸 Current Behavior

Dev server will serve any path unregonized with index.html, and many magic seems to be confusing to me.

Feature

Most helpful comment

running into this as well

I use parcel to build a simple html css js page (using it for minification, autoprefixer, scss, etc.)
I used to run it like this parcel index.html

Just noticed the multiple page support so decided to add a privacy.html and now run parcel as parcel index.html privacy.html and build as such parcel build index.html privacy.html --public-url . --out-dir docs/ (for github pages support)

On github pages all works as expected (going to the root path servers index.html and /privacy the privacy policy. However using the server I can only access the pages with localhost:1234/index.html and localhost:1234/privacy.html

Is this the expected behaviour?

All 8 comments

This is to support Single Page Applications, as these might have internal front-end routing, that can't work without redirecting everything to the index.html file

Thanks for your reply. but is serve index.html with request like js.8e7f6a41.js as index.html seems to be rather confusing. Is there anyway to workaround that. Without resorting external package like http-server of course.

That said, I think adding a flag like --no-spa is probably not an option as that does not fit parcel's zero config philosophy.

Perhaps we can see if the extension of the request equals one of the types parcel has registered (in the parser) and return a 404 or the actual asset in that case?

This solution fits my use case perfectly, but I am not really a frontend expert. Not sure if this will break somebody else's setup.

This is to support Single Page Applications, as these might have internal front-end routing, that can't work without redirecting everything to the index.html file

maybe that could be non-default behaviour enabled by --spa-routing?

I'm running into this issue as well even on just the index page. I guess my question is why is this considered an unknown path? When on ///index.html/etc, ./bundle.0af421.js resolves to the exact same URL as /bundle.0af421.js so shouldn't it just serve the correct file like normal?

running into this as well

I use parcel to build a simple html css js page (using it for minification, autoprefixer, scss, etc.)
I used to run it like this parcel index.html

Just noticed the multiple page support so decided to add a privacy.html and now run parcel as parcel index.html privacy.html and build as such parcel build index.html privacy.html --public-url . --out-dir docs/ (for github pages support)

On github pages all works as expected (going to the root path servers index.html and /privacy the privacy policy. However using the server I can only access the pages with localhost:1234/index.html and localhost:1234/privacy.html

Is this the expected behaviour?

I too am looking for a --clean-urls type behavior (/foo->/foo.html)
rather than --spa-routing type behavior (/foo->/index.html) in some cases.

Was this page helpful?
0 / 5 - 0 ratings