umd bundle for solidjs
I want to render solidjs components in the browser without builder step. For React I do it like this with babel standalone:
<head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js" crossorigin></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js" crossorigin></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script type="text/babel" id="App.jsx"> window.App = function App() { return ( React.createElement('div', null, React.createElement('h1', null, 'Random header text'), React.createElement('p', null, 'This is a longer paragraph consisting of two to three sentences. It serves as placeholder text to demonstrate how the descriptor handles multi-sentence content. You can replace this with any content you like.'), React.createElement(Userform, {style: {display: 'flex', flexDirection: 'row'}}) ) ); }; window.Userform = function Userform(props) { return ( React.createElement('div', {style: props.style}, React.createElement('label', null, 'Username:'), React.createElement('input', {placeholder: 'Your Github username'}) ) ); }; </script> </head>Solid also ships babel preset that I could use. The problem is that solid doesn't ship umd bundle, and babel standalone only works with global vars (not esm exports). Any way for me to generate Solid's umd bable myself from sources?
7 Replies
solid has 2 ways of doing bundleless:
solid/h
and solid/html
.
solid/h
looks quite similar to react's createElement
:
solid/html
is a tag template literal:
for these methods you do not need babel or any additional tooling
i am a bit confused by your example: you mention you need babel standalone
, but then you are using React.createElement
directly in the snippet. do you still need babel then? i would assume as long as you don't use jsx you don't need babel?thanks for the repsponse, @bigmistqke !
you mention you need babel standalone, but then you are using React.createElement directly in the snippet.yeah, my bad, it's JSX usually there, so I'd like to compile in browser Solid's JSX using a preset for babbel standalone
gotcha. in that case: mb you can try out https://esm.sh/babel-preset-solid
esm.sh
already does a transformation for making things esm friendlyI managed to put together this, but still there's an error
I notcied there's a solid playground, I assume it somehow does the compilatio in the browser?
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
this worked with
h
, thanks for the hint
still would be good to figure out how to run it with JSX in browser compilationJust use some normal ES modules