-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
scripts: js minify #500
Comments
If this is to be considered, I think esbuild may be a better tool to rely on. |
You could use your favorite javascript minifier in a build step, and point your <script> tags to the foo.min.js file instead of foo.js. |
Following the templ guide, in my example, every custom templ component (if needed) has its own script part. Is this a design issue (from my own) I havent considered? |
Currently the only way to achieve this would be to ditch templ I think that the code in templ scripts should be small so may not really benefit from minification, which I believe is ideal for projects with large JS assets which are usually inflated by dependencies. |
I'm playing around with the use of tdewolff's JS parser to enable a new type of It would open up the door to this sort of thing in templ, and maybe supersede script and CSS templates over the longer term:
So yes, tdewolff's minifier might work nicely. |
It would also be great if templ's LSP can perhaps also proxy to another LSP for JS (similar to how Go code is checked with |
That is also something that I'm looking at @stephenafamo - I put an example of what that could look like at #498 (comment) The example demonstrates the concept of being able to have just the HTML rendered, which would massively simplify the use of HTML and other LSPs. |
I think the same applies to css. Being able to run the component level css through postcss at generate time opens up a whole ecosystem of plugins without templ having to be aware. So maybe a hook/middleware in the generate logic that calls out to plugins, allowing custom logic? Alternatively, a vite plugin that triggers I'm going to dig around under the hood today and see what that would take. |
Due to the recommendation to move away from script templates I think we can close this. The decision is due to scenarios exactly like this, we cannot support all of the workflows that people like to process js and css, so making the interop with the outputs of said processes should be the priority. |
It's not recommended to pass go values to scripts anymore? Edit: never mind, please ignore my comment. I didn't read the full documentation https://templ.guide/syntax-and-usage/script-templates#passing-server-side-data-to-scripts |
first of all, amazing tool!
is it possible to implement some minify tools, especially regarding the javascript code. Seems like a good go library exists:
https://github.com/tdewolff/minify
The text was updated successfully, but these errors were encountered: