gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.38k stars 7.49k forks source link

Support ESBuild options `JSXImportSource` and `JSX` #12118

Closed baltpeter closed 7 months ago

baltpeter commented 8 months ago

Hugo already has support for passing the JSXFactory and JSXFragment options to ESBuild:

https://github.com/gohugoio/hugo/blob/16406d9d77cb4861bba9df8ca39e7dadfe41eb45/resources/resource_transformers/js/options.go#L416-L417

These are unfortunately pretty unergonomic when using Preact. If I use the options "JSXFactory" "h" "JSXFragment" "Fragment", I have to prepend an (otherwise unused) import { h, Fragment } from 'preact'; before every JSX file.

It would probably be possible to work around that using inject, but ESBuild has two newer options that don't require such workarounds anymore, JSXImportSource and JSX: https://esbuild.github.io/api/#jsx-import-source

I would appreciate if it was possible to set these through Hugo. Currently, the only way I've seen to set these would be on a per-file level like this:

// @jsxImportSource preact
// @jsxRuntime automatic

If there is interest in supporting those two options, I'm happy to submit a PR. Thanks!

bep commented 8 months ago

I'm happy to submit a PR. Thanks!

Please do.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.