Hacker News new | ask | show | jobs
by spankalee 1124 days ago
Have you tried Lit yet? It gives you a reactive base class and declarative templates. Plain JS and no build step (or you can use TypeScript).
1 comments

I played with it a little bit when you told me a few months ago it supports buildless.[0]

The thing that dissuaded me is that it seems like it forces me to write my template HTML in strings, so I lose VS Code syntax highlighting and Prettier auto-formatting. I tried looking for VS Code / Prettier plugins but didn't see anything.

Is there a way in Lit to write the templates in regular HTML rather than a string?

[0] https://news.ycombinator.com/item?id=34828992

The lit-plugin in for VS Code offers syntax highlighting, jumpt-to-definition, etc: https://marketplace.visualstudio.com/items?itemName=runem.li...

Prettier already supports HTML in html`` strings, likewise, CSS.

> Is there a way in Lit to write the templates in regular HTML rather than a string?

This would require a compiler. You would need to load the HTML into the JS module graph and JS can't do that yet, though there is a proposal for it: https://github.com/WICG/webcomponents/blob/gh-pages/proposal...

Template in HTML also have the problem of the data not being in scope as it is in JS, and there not being an expression language. So you ned up having to re-implement a lot of JS embedded into the HTML syntax, which then preferences a compiler-based approach to make fast. It turns out to be a lot simpler to embed HTML in JS.