Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--no-content-hash isn't working correctly #5894

Closed
mischnic opened this issue Feb 20, 2021 · 18 comments
Closed

--no-content-hash isn't working correctly #5894

mischnic opened this issue Feb 20, 2021 · 18 comments

Comments

@mischnic
Copy link
Member

🐛 bug report

--no-content-hash doesn't seem to have an effect.

😯 Current Behavior

When changing the contents of an JS asset, the bundle hash changes.

🤔 Expected Behavior

Bundle name hash shouldn't change

💻 Code Sample

parcel build index.html --no-content-hash

<script src="index.js"></script>
console.log(123); // <- change this

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.603
@Kangaroux

This comment has been minimized.

@GreatState

This comment has been minimized.

@mischnic

This comment has been minimized.

@mischnic mischnic changed the title --no-content-hash isn't working correclty --no-content-hash isn't working correctly Mar 1, 2021
@GreatState
Copy link

Excellent thanks for the clarification

@Kangaroux
Copy link

No. --no-content-hash still adds hashes, it's just that they are constant (and not changing based on the file contents)

The help docs say it shouldn't include hashes.

--no-content-hash              disable content hashing

@mischnic
Copy link
Member Author

mischnic commented Mar 1, 2021

No, as I've said, it "disables content hashing". It doesn't "disable hashing".

But I admit that the docs should make this clearer

@Kangaroux
Copy link

I don't see the value of having a static hash if it doesn't match the content. Why isn't it completely disabled?

@mischnic
Copy link
Member Author

mischnic commented Mar 1, 2021

See #2056

@devongovett
Copy link
Member

Appears to be working in the latest nightly.

@RichardJECooke
Copy link

RichardJECooke commented May 9, 2023

Even though I use --no-content-hash my filenames still change. Version 2.83. Look:

> rm -r dist || rm -r .parcel-cache || true && parcel build --no-content-hash src/index.html`

✨ Built in 15.71s

dist/index.html                   1.33 KB    17.54s
dist/logo.4f32dfb3.svg              355 B    17.53s
dist/app.webmanifest                450 B     2.09s
dist/appIcon512.7666cacc.png      6.09 KB    17.29s
dist/index.178894d8.css           4.15 KB     2.32s
dist/index.c2dc1f85.js          855.98 KB    13.90s

> rm -r dist || rm -r .parcel-cache || true && parcel build --no-content-hash --no-source-maps src/index.html

✨ Built in 20.37s

dist/index.html                   1.33 KB    13.59s
dist/logo.fde9f7fd.svg              355 B    13.58s
dist/app.webmanifest                450 B     837ms
dist/appIcon512.6a4fe200.png      6.09 KB    13.27s
dist/index.0c63f772.css            4.1 KB     1.13s
dist/index.62ba04f6.js          855.92 KB    13.31s

Is there a way to not have hashes in the filename please? It's confusing when trying to learn service workers and caching.

@mischnic
Copy link
Member Author

mischnic commented May 9, 2023

The hash will still be dependent on some build options. It's just that "build", "change file", "build" won't change the hash.

@RichardJECooke
Copy link

The hash will still be dependent on some build options. It's just that "build", "change file", "build" won't change the hash.

Ok, so how do I refer to these files correctly in my PWA's service worker if I don't want to have them go missing if I change something in my build please?

@mischnic
Copy link
Member Author

mischnic commented May 9, 2023

You can do import {manifest, version} from '@parcel/service-worker'; to get a file list, see https://parceljs.org/languages/javascript/#service-workers

@RichardJECooke
Copy link

RichardJECooke commented May 12, 2023

Ok, the hashes are definitely not the same. I haven't changed any of my build commands and you can see here the filenames I cached are not the ones the dev server is supplying:
image

Secondly, the service workers documentation for Parcel is almost nonexistent - https://parceljs.org/languages/javascript/#service-workers. How are filenames managed and added? The sample just imports something called manifest, but how does it get the filenames?

@RichardJECooke
Copy link

You can use this plugin to fully remove content hashes from your output - https://www.npmjs.com/package/parcel-namer-hashless

@RichardJECooke
Copy link

RichardJECooke commented May 18, 2023

Ok, no, that plugin doesn't work, Parcel gives the error AssertionError [ERR_ASSERTION]: Bundles must have unique names even though the final output has no duplicates. The engine is a bit broken.

@mischnic
Copy link
Member Author

mischnic commented May 18, 2023

The sample just imports something called manifest, but how does it get the filenames?

A parcel plugin automatically injects a manifest.
https://github.com/parcel-bundler/parcel/blob/e46be4dfed1f71dbb1fa04c34cc23ff4eeecfa0f/packages/runtimes/service-worker/src/ServiceWorkerRuntime.js

@Taxi4you
Copy link

Taxi4you commented May 25, 2023

+1

I don't want hash, why Parcel forces it?
I just want index.js bundle and thats it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants