Created
October 6, 2020 18:58
-
-
Save ikbelkirasan/ec8afb5008da177477c951de2fecb5ff to your computer and use it in GitHub Desktop.
Require lodash from CDN in Node
This file contains 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
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