Thanks a lot @jmooring for the quick response.
This works great. I tried and tested this.
There’s one issue I saw while using this template:
Setup
inline/test.ts
const longNameforFunction = (): string => {
console.log('Hello World');
return 'Ended';
}
const variable = `It has ${longNameforFunction()}`;
console.log(variable);
HTML template
{{ $inline := resources.Get "inline/test.ts" | js.Build $esbuild_options }}
{{ with $inline }}
<script>
{{ .Content | safeJS }}
</script>
{{ end }}
Result
The above template, with $esbuild_options
generates:
<script>var longNameforFunction = () => (console.log("Hello World"), "Ended"), variable = `It has ${longNameforFunction()}`; console.log(variable)</script>
which works but isn’t uglified/minified, as per the esbuild options I provide to the pipe function.
New Setup
When I try adding one more js.Build
pipe to the above HTML template, .Content
provides a proper output.
New HTML Template
<!-- There's this `js.Build` extra pipe added to this template, compared to the previous one -->
{{ $inline := resources.Get "inline/test.ts" | js.Build $esbuild_options | js.Build }}
{{ with $inline }}
<script>
{{ .Content | safeJS }}
</script>
{{ end }}
Result:
<script>(() => { var e = () => (console.log("Hello World"), "Ended"), t = `It has ${e()}`; console.log(t) })()</script>
The result now is properly uglified and has less number of characters than before.
My esbuild config looks like this:
{
"target": "es2019",
"defines": {},
"format": "esm",
"minify": true
}