Skip to content

Instantly share code, notes, and snippets.

@allain
Last active October 7, 2017 03:07
Show Gist options
  • Save allain/cf1e5abc9d1a22b65abbdfc0c4515e05 to your computer and use it in GitHub Desktop.
Save allain/cf1e5abc9d1a22b65abbdfc0c4515e05 to your computer and use it in GitHub Desktop.
use npmjs from the browser
console.log('installed: need, crave')
crave = m => fetch(`https://wzrd.in/bundle/${m}@latest/`)
.then(r => r.text())
.then(eval)
.then(() => require(m))
need = m => {crave(m).then(r => {
window[m] = r
console.log(`installed: ${m}`)
})}
// based on: https://gist.github.com/mathisonian/c325dbe02ea4d6880c4e
// usage once run in the browser (using a bookmarklet: https://bookmarkify.it/7166)
// folktale gets downloaded but not made available globally
crave('folktale').then(console.log)
// folktale gets installed globally
need('folktale')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment