Last active
October 7, 2025 16:07
-
-
Save loucyx/884a22493dc95ef76c4adf5b2202cf50 to your computer and use it in GitHub Desktop.
Bookmarklet to have a tiny "AMD" require implementation in the global scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:globalThis.require??=(p,c)=>Promise.all(p.map(i=>import(i.replace(/^(\w{3}):/,(_,m)=>`//esm.sh/${m==="npm"?"":`${m}/`}`)))).then(c); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(["npm:htm/preact", "npm:preact", "npm:preact/hooks"], ([ | |
| { html }, | |
| { render }, | |
| { useState }, | |
| ]) => { | |
| const Counter = () => { | |
| const [count, setCount] = useState(0); | |
| return html` | |
| <button onClick=${() => setCount(count + 1)}> | |
| Clicked ${count} times | |
| </button> | |
| `; | |
| }; | |
| render(html`<${Counter} />`, document.body); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| globalThis.require ??= (paths, callback) => | |
| Promise.all( | |
| paths.map( | |
| (path) => | |
| import( | |
| path.replace( | |
| /^(\w{3}):/, | |
| (_, match) => | |
| `//esm.sh/${match === "npm" ? "" : `${match}/`}`, | |
| ) | |
| ), | |
| ), | |
| ).then(callback); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment