bun-plugin-html icon indicating copy to clipboard operation
bun-plugin-html copied to clipboard

Assets naming

Open gouz opened this issue 1 year ago • 6 comments

Hi, thanks for your plugin.

When I build without your plugin, Bun rename my css and js files with an hash if I set the parameter naming: "[dir]/[name]-[hash].[ext]", but with your plugin names aren't changed.

Do you know how to do that ?

Thanks

gouz avatar Mar 03 '24 22:03 gouz

Hey @gouz

Thank you for reporting this issue! To be honest it's because I didn't implement this. I could implement this for you, but I'd need to do some research to make sure I'm implementing this right. Do you have a specific use case in mind that I could make sure my implementation works properly for it?

BjornTheProgrammer avatar Mar 03 '24 22:03 BjornTheProgrammer

Thanks for your quick response ;)

I'll prepare you a usecase quickly

gouz avatar Mar 03 '24 22:03 gouz

Imagine you have the following index.html:

<!DOCTYPE html>
<html>
<head>
<link href="styles.css" rel="stylesheet" />
</head>
<body>
<h1>Test</h1>
</body>
</html>

If styles.csscontains h1 { color: red; }, the generated file will be renamed in a styles-SHA, and in the index.html the link will point to this file. If the content change, a new sha is calculated, then no cache ;)

It works for css & js

gouz avatar Mar 07 '24 08:03 gouz

@gouz

Sorry this is taking a while. I still have to figure out a few things about the implementation. Specifically how to treat chunks and assets with the naming rules. I want to ensure everything works properly. Just know I'm still working on this right now.

BjornTheProgrammer avatar Mar 09 '24 06:03 BjornTheProgrammer

No problem. Thanks

gouz avatar Mar 09 '24 07:03 gouz

great if it's ready, then i could switch from my packup version ( https://github.com/mindon/packup ) to bun with html plugin!

mindon avatar Apr 15 '24 02:04 mindon

@mindon @gouz This has now been fixed as part of v2.1.0. Sorry for the long wait.

It requires that you upgrade to Bun v1.1.34, since it relies on #14717, which fixed Bun's bug #8280. I was waiting for this issue to be fixed before rewriting the code base, but nobody did, so I decided to submit a pr to fix it. Now that it has been merged, I was able to rewrite the code base to support naming, you can read more about it here.

Please let me know if you would like to see any other additional features as part of this, and thank you for being patient!

BjornTheProgrammer avatar Nov 05 '24 12:11 BjornTheProgrammer

Thanks a lot, no problem for the wait, it's an opensource projet and you're not paid for.

gouz avatar Nov 05 '24 12:11 gouz