oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.48k stars 2.71k forks source link

Include optional template minification behind --minify #3024

Open Kruithne opened 1 year ago

Kruithne commented 1 year ago

What is the problem this feature would solve?

When using the bun build --minify, template literals are not minified. This makes sense from a safety standpoint, however an optional method of at least compacting the whitespace within templates would be beneficial. On a large codebase with many components, the minified result contains large inflated sections of HTML which could reduce the bundle size considerably.

image

What is the feature you are proposing to solve the problem?

Optionally minify whitespace within HTML template literals. This would need to be done with some safety to prevent intentional whitespace within elements from being removed.

What alternatives have you considered?

No response

paperdave commented 1 week ago

stuff like this should be solved by macros; in this case you can have a vue macro. we cant ever unconditionally do this on all template strings, because it will most definitely break library code.

i can't close the issue because macros still have servere issues affecting this use case:

this is a problem i noticed when working on https://bun.report, which doesn't use a framework nor any tooling; it is just a call to Bun.build. the frontend code includes dynamic HTML strings:

image

the way i worked around it was to use a crazy regular expression to minify the templates anyways.

image

this type of hack works for small projects but wont ever scale up. the macro system is begging to be used for something like this. unfortunately, i don't have time to implement the above changes anytime soon, but i do want to serialize my thoughts so they're in writing. apologies for long delay in this.