preact as global singleton for no-build components? #3966
-
Hi, apologies for the super noob question, esmodules are very new to me and i'm still trying to wrap my head around the concept. First a little bit of context: This setup has worked great but i recently started to wonder if there was a way to make reusable, non-build, react-like page components and found very promising libraries like preact / atomico / etc but all non-build options so far seem to revolve around the module concept while hosted in skypackage or unkpg. The main issue with modules, for me, is that it doesn't play nicely with the whole preloader setup mentioned above. It'll just load and execute as soon as the page loads. My question is, is there a way to use libraries like preact/htm where they can be hosted locally, loaded, and picked up/used as singletons from the global scope, without the whole module-based setup? Is this some sort of anti-pattern/bad practice type of deal and that's why I can't seem to find a solution or is there something else happening where this must be setup as modules if we want to take the no-build approach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Is this all you're looking for? https://jsfiddle.net/t9xy01kh/1/
Import maps may be of interest. Define once, everything else will just consume from it. https://jsfiddle.net/aeghk5p8/
It's not really clear to me why you think ESM will not work for your situation, or why you're trying to control module loading the way you are, but yes, ESM is the way the ecosystem is going and it's going to generally be nicer to lean into built-in functionality than trying to build it out yourself. |
Beta Was this translation helpful? Give feedback.
Is this all you're looking for?
https://jsfiddle.net/t9xy01kh/1/
Import maps may be of interest. Define once, everything else will just consume from it.
https://jsfiddle.net/aeghk5p8/
It's not really clear to me why you think ESM will not work for your situation, or why you're trying to control module loading the way you are, but yes, ESM is the way the ecosystem is going and it's going to generally be nicer to l…