Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

feat: new minify-js arg for templ generate #880

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

garrettladley
Copy link
Contributor

@garrettladley garrettladley commented Aug 11, 2024

completed version of @cornejongs draft pr here

handled templ Component() { <script ...>...</script> } and script Component() { ... } cases.

i've tested this locally by comparing outputs when -minify-js=true vs -minify-js=false with go run ./cmd/templ generate -include-version=false -f [file] -minify-js=[bool]

do you have any ideas / starting points on how to write tests for an argument to templ generate? i didn't see any other examples in the project

@garrettladley
Copy link
Contributor Author

also, does anyone know how to fix the CI/build step? running into the following error:
generator/generator.go:20:2: cannot find module providing package github.com/tdewolff/minify/v2: import lookup disabled by -mod=vendor

@cornejong
Copy link
Contributor

cornejong commented Aug 17, 2024

Honestly, i kinda forgot that i started working on that 😅
Took a look at it yesterday and today, and finished my implementation #772 .
It differs from yours in a few ways:

  • Add CSS minification as well (why not?) --minify-css
  • Script tag src attribute check. No need to run the minifier on tags that load in scripts remotely.
  • Script tag type attribute check. Not all script tags neccesarily contain javascript / minifiable contents.

The attribute checks are build on the assumption that those attribute are defined using a constant/static attribute declaration (not using a spread or conditional declaration). Mostly because of the way those are implemented right now. there is no easy check if those attributes are present/set at generation. I'll leave it up to @a-h to decide if that's acceptable or not. Might look into making that a bit more bomb proof in the future. For now it seems to work quite well.

Any script tag content type that is supported by the minifier (tdewolff/minify/v2 ) will be minified. including Json content.

Css minification is only applied to <style> tags. The css SomeClass() { ... } syntax already seemd minified.

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