bikeshaving / crank

The Just JavaScript Framework
https://crank.js.org
MIT License
2.7k stars 75 forks source link

Export `renderer` and `Renderer` based on environment from `@b9g/crank/standalone` #256

Open brainkim opened 1 year ago

brainkim commented 1 year ago

It’s annoying to import the new jsx template tag from standalone, and also have to import a renderer for the respective environment. I’m wondering if we can use some sort of environment detection mechanism to have the correct one imported.

Before:

import {jsx} from "@b9g/crank/standalone";
import {renderer} from "@b9g/crank/dom";

renderer.render(jsx`<div id="hello">Hello world</div>`, document.body);

After:

import {jsx, renderer} from "@b9g/crank/standalone";

renderer.render(jsx`<div id="hello">Hello world</div>`, document.body);

How do we determine environment? I don’t like using non-standard package.json exports, and exports conditions are really confusing. I honestly just want to do top-level await imports.