Created
August 17, 2017 13:45
-
-
Save wildeyes/7cd807a326e6441cdc6587d3cf7bec93 to your computer and use it in GitHub Desktop.
Load into the browser's console (dev tools) any npm package
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
// 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