Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parcel JS. Use of --public-url option

I am using Parcel JS for a personal project and I am really confused by this option:

--public-url

Here is the documentation: https://en.parceljs.org/cli.html#options

which is really scarce.

1) What is the main use of it?
2) It says that it is available in: serve, watch and build.
Is there any difference between these 3 options while using --public-url?
3) And last but not least, how --public-url and --out-dir work together? Is there any limitation on the setup when we use both options at the same time?

Thanks.

like image 1000
jet2016 Avatar asked Jan 20 '26 11:01

jet2016


1 Answers

  1. --public-url is used to specify from where the bundled assets are served.

As an example:

The default value is --public-url /, which generates tags like this.

<script src="/src.133713ex.js">

Which doesn't work if the site is not served from the domains root.
E.g. on a Github Pages site where the URLs are username.github.io/project-name/, here you would need to serve them from the index.html files location.

That's where --public-url comes in to play:

--public-url ./

By adding this to our build options we change the generated tag to the following, which would work.

<script src="src.133713ex.js">
  1. It just means you can use it with every way there is to start a parcel process.

  2. Yes they do work together! --out-dir just defines the directory where the bundled files are generated (default is /dist) and --public-url functions as explained above.

like image 65
kuro Avatar answered Jan 23 '26 02:01

kuro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!