Use typescript instead of javascript
joeyak opened this issue · comments
Perhaps we look at using the esbuild api to transform typescript into a javascript string at startup instead of reading from a js file.
https://pkg.go.dev/github.com/evanw/esbuild/pkg/api#hdr-Transform_API
Considerations:
- This might remove real time editing of the javascript....but currently the html is only loaded at runtime so might be a mute point.
- Make it transform into a single file to make importing simpler
- Do the transform with strings instead of building with files
- This would work well when/if the html templates get embedded into the program
This might remove real time editing of the javascript....but currently the html is only loaded at runtime so might be a mute point.
I'm not sure what you mean by real time editing of the JS. Do you mean for debugging?
Also, I've thought about it some more and I'm not against using typescript. How would it work logistically? Would the TS be minified/compiled to JS at compile time? Or would the TS be minified/compiled at runtime when it's being served to a client?
By real time editing, I mean you can't just edit the js file and refresh the browser. How the program currently works, the css, emotes, js, etc (static files) are served live while the html files are loaded at startup.
We could do it at compile time, but that adds another step to the build pipeline, while doing the transforms in memory would make setup easier.
I was thinking we could somewhere in the main function do
// load jsx from disk/embedded
result := api.Transform(jsx, ...);
// the javascript handler outputing result.Code
with the example in the docs showing
func main() {
jsx := `
import * as React from 'react'
import * as ReactDOM from 'react-dom'
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
`
result := api.Transform(jsx, api.TransformOptions{
Loader: api.LoaderJSX,
})
fmt.Printf("%d errors and %d warnings\n",
len(result.Errors), len(result.Warnings))
os.Stdout.Write(result.Code)
}```
After testing out typescript transforming with another project, this will probably be more work than needed, so gonna close this.