developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.67k stars 170 forks source link

import mini as es-module #161

Closed zaceno closed 4 years ago

zaceno commented 4 years ago

I would like to use the mini-build as an es-module. In other words something like this:

import {h, app} from 'https://unpkg.com/hyperapp'
import htm from 'https://unpkg.com/htm/mini'
const html = htm.bind(h)

What I wrote above doesn't work unfortunately. Is there something else, similar I could write?

The best I've been able to come up with is this:

import {h, app} from 'https://unpkg.com/hyperapp'
import 'https://unpkg.com/htm/mini' //puts `htm` in global scope
const html = htm.bind(h)

... but I'd prefer not to put things in the global scope.

Strictly speaking, it's not the smaller size I'm after with the mini-version, but the fact that it doesn't do the caching. So... if there isn't a way to import the mini version as an es-module, please consider this a feature request to be able to turn off caching in regular htm.

(Suggestion: const html = htm.bind(h, {caching: false}))

Thanks!

Kanaye commented 4 years ago

Can you try out

import htm from 'https://unpkg.com/htm/mini/index.module.js';

?

[Edit: fixed wrong link 😄 ]

zaceno commented 4 years ago

@Kanaye Thanks! That works! 👍