v118
in v118, we added an experimental API that allows you to build a module with custom input(code).
import build, { esm } from "https://esm.sh/build"
const ret = await esm`
/* @jsx h */
import { h } from "[email protected]";
import { renderToString } from "[email protected]";
export default () => renderToString(<h1>Hello world!</h1>);
`
// use `build` function
const ret = await build({
dependencies: {
"preact": "^10.13.2",
"preact-render-to-string": "^6.0.2"
},
code: `
/* @jsx h */
import { h } from "preact";
import { renderToString } from "preact-render-to-string";
export default () => renderToString(<h1>Hello world!</h1>);
`
})
const { default: render } = await import(ret.url)
render() // "<h1>Hello world!</h1>"
// use bundled module
const { default: render } = await import(ret.bundleUrl)
Changelog: