Parcel: How to generate output file with hash in name

Created on 14 Jun 2018  ยท  3Comments  ยท  Source: parcel-bundler/parcel

โ” Question

How to generate output file with hash in name

๐Ÿ”ฆ Context

Thanks for your great work
I'm building a library with parcel which can run in browser. It has an entry file index.js written in es6
I build it with parcel build index.js and want something like index.hash.js but always get index.js
How can I get that index.hash.js file ?

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.8.1|
| Node |6.14.2|
| npm/Yarn |1.6.0|
| Operating System |Ubuntu 16.04|

Most helpful comment

Hi,

@devongovett I have the following szenario:

I use parcel to bundle the client files for an ASP.NET core MVC site. I run parcel with

parcel watch src/*.ts src/*.less --out-dir ../wwwroot/dist

in my .cshtml I reference the files like so:

<script type="text/javascript" asp-src-include="~/dist/site.*.js"></script>

The hash in the name would be nice to have to overcome some caching problems while deployment to production.

I think a switch like --force-hash or --hash-files would be a good option to enable a scenario like this.
I am quite new to parcel, maybe I got something wrong here, so please give me a push in the rigt direction.

Thanks,
KirK

All 3 comments

This already happens by default when building for production. However, we do not hash entry points because they might be linked to directly. If you point parcel at your HTML file instead of a JS entry point, it will automatically hash your linked JS files.

@devongovett thanks for your answer
When I build using parcel build index.html, it generates index.html and src.hash.js. I want the .js file to be index.hash.js. How can I get it

Hi,

@devongovett I have the following szenario:

I use parcel to bundle the client files for an ASP.NET core MVC site. I run parcel with

parcel watch src/*.ts src/*.less --out-dir ../wwwroot/dist

in my .cshtml I reference the files like so:

<script type="text/javascript" asp-src-include="~/dist/site.*.js"></script>

The hash in the name would be nice to have to overcome some caching problems while deployment to production.

I think a switch like --force-hash or --hash-files would be a good option to enable a scenario like this.
I am quite new to parcel, maybe I got something wrong here, so please give me a push in the rigt direction.

Thanks,
KirK

Was this page helpful?
0 / 5 - 0 ratings

Related issues

will-stone picture will-stone  ยท  3Comments

davidnagli picture davidnagli  ยท  3Comments

dsky1990 picture dsky1990  ยท  3Comments

medhatdawoud picture medhatdawoud  ยท  3Comments

Niggler picture Niggler  ยท  3Comments