tonic-universal
Experimental isomorphic exports of @socketsupply/tonic. Still experimenting with this approach.
npm install tonic-universal
Usage
Use @socketsupply/tonic
or tonic-ssr
from a single import identifier depending on then environment you are running.
// Shared codepaths between node and the browser.
import Tonic from 'tonic-universal'
class MyGreeting extends Tonic {
render () {
return this.html`<div>Hello, World.</div>`
}
}
Tonic.add(MyGreeting, 'my-greeting')
How
tonic-universal
works by utilizing environment specific exports fields so that you can have dependency injection at the built-in module resolver layer.
It supports the following export fields:
main
(cjs node)TODO: Release a dual pacakgebrowser
(cjs browser)@socketsupply/tonic
to suppor this.exports.import
(esm node)exports.reqire
(cjs node)exports.browser
(esm browser)
When writing components, import @socketsupply/tonic
.
If you have a common codepath that registers components in node and the browser, import tonic-universal
.
License
MIT