Skip to content

Instantly share code, notes, and snippets.

@wildeyes
Created August 17, 2017 13:45
Show Gist options
  • Save wildeyes/7cd807a326e6441cdc6587d3cf7bec93 to your computer and use it in GitHub Desktop.
Save wildeyes/7cd807a326e6441cdc6587d3cf7bec93 to your computer and use it in GitHub Desktop.
Load into the browser's console (dev tools) any npm package
// Add a require function that works just like in node, but can require any npm package, with it's version too.
// example 1 : require('lodash'); instanceof window.lodash === 'object'
function require(npmModule) {
console.info(`Attempting to load ${npmModule}...`);
var version = npmModule.indexOf('@') !== -1 ? '' : '@latest';
var body = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = `https://wzrd.in/standalone/${npmModule}${version}`;
script.onload = () => console.log(`Loaded ${npmModule}!`)
body.appendChild(script);
}
// Or, drag this into your bookmark bar.
javascript:function require(npmModule){console.info(`Attempting to load ${npmModule}...`);var version=npmModule.indexOf('@')!==-1?'':'@latest';var body=document.getElementsByTagName('body')[0];var script=document.createElement('script');script.type='text/javascript';script.src=`https://wzrd.in/standalone/${npmModule}${version}`;script.onload=()=>console.log(`Loaded ${npmModule}!`)
body.appendChild(script)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment