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

config: support hash option (#40) #41

Merged
merged 2 commits into from
Jul 4, 2023
Merged

Conversation

vpanta
Copy link
Contributor

@vpanta vpanta commented May 30, 2023

Support a new option: hash
This will cause the appending of a hash based on the output's JSON metadata, so that upon new releases there is a cache-busting effect. Similar to html-webpack-plugin's hash option.

src/index.ts Outdated
@@ -168,6 +170,9 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui
const htmlFileDirectory = posixJoin(outDir, htmlFileConfiguration.filename)
targetPath = path.relative(path.dirname(htmlFileDirectory), filepath)
}
if (htmlFileConfiguration.hash) {
targetPath = `${targetPath}?${crypto.createHash('md5').update(JSON.stringify(outputFile)).digest("hex")}`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's enough to base the cache-busting effect on the metadata. While there is probably not a high probability for this, if you just change a typo in one of your files and the number of characters stays the same, the metadata won't change, and the hash would not change :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I thought about that but thought this might be close enough. If we don't care for reproducible builds, we could salt with the build time as well (or just do the build timestamp instead of the metafile info).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to either hash the current time, or to allow folks to pass through a string for the base of the hash (such as the git commit SHA).

@craftamap craftamap merged commit 64010ce into craftamap:master Jul 4, 2023
@craftamap
Copy link
Owner

Thanks for the contribution :)

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

Successfully merging this pull request may close these issues.

2 participants