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

build and watch produce different hashes #10059

Closed
srl295 opened this issue Dec 26, 2024 · 3 comments
Closed

build and watch produce different hashes #10059

srl295 opened this issue Dec 26, 2024 · 3 comments

Comments

@srl295
Copy link

srl295 commented Dec 26, 2024

πŸ› bug report

parcel build … --no-content-hash and parcel watch … --no-content-hash produce different filename hashes.

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

 npx parcel build --target=default --cache-dir=.parcel-cache --no-content-hash

πŸ€” Expected Behavior

Expect the same files with build and watch

😯 Current Behavior

build

$ npx parcel build --target=default --cache-dir=.parcel-cache --no-content-hash
✨ Built in 247ms
…
$ ls build/*
  • build/index.2f8490e0.js
  • build/index.2f8490e0.js.map
  • build/index.89a9d63e.css
  • build/index.89a9d63e.css.map
  • build/index.html

watch

$ npx parcel watch --target=default --cache-dir=.parcel-cache --no-content-hash
✨ Built in 31ms
^C
$ ls build/*
  • build/index.4ff28c68.js
  • build/index.4ff28c68.js.map
  • build/index.b5742bdb.css
  • build/index.b5742bdb.css.map
  • build/index.html

πŸ’ Possible Solution

while [[ 1 = 1 ]]; do npx parcel build --target=default --cache-dir=.parcel-cache --no-content-hash; echo Hit Enter to Rebuild; read junk; done

Workaround: I might also see if I can mutate the parcel-generated index.html in memory to serve my purposes.

πŸ”¦ Context

I'm trying to iterate on the files and noticed that they didn't seem to be changing when using watch.

And for more context, I am loading the files from a VSCode extension webview, so I have a dynamically generated index.html I need to use that includes some additional pieces.

πŸ’» Code Sample

package.json here - note, it's in an npm workspace.

🌍 Your Environment

Software Version(s)
Parcel 2.13.2
Node 18.20.4
npm/Yarn 10.7.0
Operating System mac x86-64 15.1.1
@devongovett
Copy link
Member

parcel build produces a production build by default. parcel watch produces a development build. When you use --no-content-hash, the hashes are based on the ids of the assets, which are derived from a hash of a bunch of things including the file path, environment (including browser/node, output format, minification settings), etc. The environment is different between development and production, therefore the ids are different.

I'm not quite sure why you are expecting the ids to be the same. As long as the end result references the correct bundles it shouldn't matter right? Why is this an issue for you?

@srl295
Copy link
Author

srl295 commented Jan 11, 2025

parcel build produces a production build by default. parcel watch produces a development build. When you use --no-content-hash, the hashes are based on the ids of the assets, which are derived from a hash of a bunch of things including the file path, environment (including browser/node, output format, minification settings), etc. The environment is different between development and production, therefore the ids are different.

I'm not quite sure why you are expecting the ids to be the same. As long as the end result references the correct bundles it shouldn't matter right? Why is this an issue for you?

I can't use the index.html as is because I need to add some tags that I won't know at build time. (Content security) So I was trying to use the assets directly and ignore the generated index.html.

I've gone with a more complicated rewriting of the parcel generated index.html (linked above) so I no longer am stuck on this issue.

@devongovett
Copy link
Member

Do you need the HTML file at all then? Maybe you could make your JS file(s) the entry point of your parcel build. Then you'll get predictable and completely unhashed output files.

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

No branches or pull requests

2 participants