Skip to content

Instantly share code, notes, and snippets.

@ikbelkirasan
Created October 6, 2020 18:58
Show Gist options
  • Save ikbelkirasan/ec8afb5008da177477c951de2fecb5ff to your computer and use it in GitHub Desktop.
Save ikbelkirasan/ec8afb5008da177477c951de2fecb5ff to your computer and use it in GitHub Desktop.
Require lodash from CDN in Node
const fetch = require("node-fetch");
const vm = require("vm");
async function requireLodash(url) {
const context = {};
const rawData = await fetch(
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"
).then((res) => res.text());
vm.runInNewContext([rawData, "global.lodash = _"].join("\n"), {
global: context,
});
return context.lodash;
}
const _ = await requireLodash(); // lodash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment