Javascript build JSX Factory

I’m trying to use Preact with Hugo v0.79.0. I’ve got everything compiling, but at runtime the error b/c I cannot figure out how to send the jsxFactory: 'h' flag to the compiler. It is trying to call React.createElement.

This is the error

Uncaught ReferenceError: React is not defined

I’ve tried adding a tsconfig.json to the project root. I’ve also tried messing with the jsconfig.json, but then found that the jsx props are not supported.

How do I pass the jsx-factory flag to esbuild?

Of course, right after I submit this I find the answer. I should’ve started with the source code. For anyone wondering, the config param is here

Here is the fix:

{{ $params := dict "foo" "bar" }}
{{ $opts := dict "targetPath" "header.js" "params" $params "target" "es2018" "JSXFactory" "h"}}

{{ $built := resources.Get "src/header.tsx" | js.Build $opts }}
<script type="text/javascript" src="{{ $built.RelPermalink }}" defer></script>
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.