Parcel: Parcel doesn't always generate index.html files in sub-directories

Created on 23 May 2018  路  5Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

When using Parcel to build and/or serve a website made of static HTML files, linking to directories doesn't work as expected. Example:

<a href="about/">About</a>

馃帥 Configuration (.babelrc, package.json, cli command)

N/A - bug is visible without any configuration files.

馃 Expected Behavior

It should generate dist/about/index.html, and clicking the "About" link should go to http://localhost:1234/about/ -- which should serve the content from about/index.html.

馃槸 Current Behavior

It does not generate dist/about/index.html, and clicking the "About" link goes to http://localhost:1234/about/ -- but it serves the content from index.html.

馃拋 Possible Solution

Generate index.html files found in a directory, and serve their content when visiting that directory URL directly.

馃敠 Context

I came upon this bug when trying to make a simple marketing website: primarily HTML and CSS, very little JS, and not a single-page applicatino.

馃捇 Code Sample

https://github.com/Kerrick/parcel-problems

Simply run parcel serve index.html and click the links to see the inconsistent behavior.

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.8.1
| Node | v10.1.0
| npm/Yarn | yarn 1.5.1
| Operating System | macOS 10.13.4

Feature RFC

Most helpful comment

not that hard to add index.html to the href property

It isn't hard to add, but it has negative side effects: after clicking the link, the browser bar shows an ugly URL (example.com/about/index.html) instead of the desired pretty URL (example.com/about/). I wouldn't mind _writing_ index.html in the href if the final output omitted it.

As it stands, it's impossible to do standard "pretty URLs" with Parcel and static HTML files. I'd definitely consider that a bug.

All 5 comments

This is because parcel detects this syntax as front-end routing or a custom back-end route instead of a html file if I'm not mistaken.

Not sure if we should fix this, not that hard to add index.html to the href property

not that hard to add index.html to the href property

It isn't hard to add, but it has negative side effects: after clicking the link, the browser bar shows an ugly URL (example.com/about/index.html) instead of the desired pretty URL (example.com/about/). I wouldn't mind _writing_ index.html in the href if the final output omitted it.

As it stands, it's impossible to do standard "pretty URLs" with Parcel and static HTML files. I'd definitely consider that a bug.

Intresting, I'll change this to RFC/Feature

I ran into the same problem. I found this: https://github.com/parcel-bundler/parcel/blob/060db2e2c56f08e223e9a9075035f0998e249763/packages/core/parcel-bundler/src/Resolver.js#L252-L253 and while it sounds very similar it doesn't seem to apply to this problem.

My current work-around is to:

$ parcel build index.html subdir/index.html

and have parcel ignore <a href="./subdir">Go to subdir</a> in the top-level HTML file but I'd like parcel to figure this out on its own and just specify one target.

I have a same problem...any updates?

Was this page helpful?
0 / 5 - 0 ratings