Parcel: Parcel --public-url ./ doesn't support scripts and links in subfolders

Created on 21 Dec 2018  Β·  10Comments  Β·  Source: parcel-bundler/parcel

πŸ› bug report

I have following file tree:

β”‚   index.html
β”‚
β”œβ”€β”€β”€donate
β”‚       step-1.html
β”‚       step-2.html
β”‚
β”œβ”€β”€β”€scripts
β”‚       main.js
β”‚
└───styles
        main.css

The step-1.html and step-2.html are both linking to the main.js and main.css. In order to get to that path I have to use ../scripts/main.js and ../styles/main.css to access them. But when bundling them with parcel using following command parcel build index.html --public-url ./, parcel bundles the output as if they are in the same folder. Anchor tags, however, are working fine.

πŸŽ› Configuration (.babelrc, package.json, cli command)

Zero config

πŸ€” Expected Behavior

Parcel should bundle to the correct paths

😯 Current Behavior

Parcel bundles to the root path for scripts and links

πŸ’» Code Sample

A full working example can be seen here:
https://github.com/advename/Parcel-error-example/tree/master

🌍 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.9.7|
| Node | 8.11.2|
| npm/Yarn | 5.6.0|
| Operating System | Windows 10 64-bit Pro|

Good First Issue Bug

Most helpful comment

This bloody bug still exists.

All 10 comments

Is it a bug or a feature?

Parcel bundles all your Javascript and CSS into separate files and places them near the processed HTML file.

It replaces all the references in your script and link tags so that they point to the correct files.

So what's the original problem you're trying to solve? All you Javascript and CSS should be working just fine.


On a separate note, it's important to understand that the output bundles (e.g. index.css) or not 1:1 to the input assets.

You could have ten different <link> tags and you would still end up with just one output file.

If you require the same asset from 2 different places, parcel creates a shared bundle for both these files. Not sure why you wouldn’t want this though as it would save you or your company a bit of money and your users loading time. As there is only one bundle that needs to get cached at the cdn and user.

In Parcel 2 we’ve taken this a big step further with extracting shared assets into shared bundles. (As most applications share a couple libraries across various entrypoints)

Sent with GitHawk

It's not about feature or "best practice" in this case.
In the code sample that I've provided, you can clearly see in the dist that parcel links to <link rel="stylesheet" href="main.04aee6b8.css"> but since I'm using apache and this project is in a subfolder, well, the correct path should be <link rel="stylesheet" href="../main.04aee6b8.css">. The same goes for the script element.

@advename ow alright, will flag it as a bug again.

In the code sample that I've provided, you can clearly see in the dist that parcel links to <link rel="stylesheet" href="main.04aee6b8.css"> but since I'm using apache and this project is in a subfolder, well, the correct path should be <link rel="stylesheet" href="../main.04aee6b8.css">. The same goes for the script element.

That reminds me of https://github.com/parcel-bundler/parcel/issues/1801 / https://github.com/parcel-bundler/parcel/pull/2518

Would someone like to tell us about the progress?

I have the same problem. What can I do now?

This bloody bug still exists.

Is there a way to work around this?
I am using static-i18n to generate localized versions of html file.
I would like to have each language version in /.
Unfortunately all parent ".." paths are ignored and output files in subdirectories reference assets without them.

Any updates on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

will-stone picture will-stone  Β·  3Comments

algebraic-brain picture algebraic-brain  Β·  3Comments

philipodev picture philipodev  Β·  3Comments

davidnagli picture davidnagli  Β·  3Comments

termhn picture termhn  Β·  3Comments