Created
February 15, 2021 04:43
-
-
Save LeetCodes/9da46f1a6de78cc0995fb6c57018f3c1 to your computer and use it in GitHub Desktop.
import browserified modules from npm
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
function require(mods,that=window){ | |
return new Promise(r=>(_=>Promise.all(_.map(function (m){return import(`https://dev.jspm.io/${m.name?m.name:m}`).then(({default:module})=>[m.var?m.var:m.replace(/\-([\w])/g,(..._)=>_[1].toUpperCase()),(module.default?module.default:module)])})).then(_=>Object.fromEntries(_.map(_=>[_[0],_[1]]))))(mods).then(_=>(Object.assign(that,_),r(_)))); | |
} | |
require([ | |
{ name: "[email protected]", var: "JSZip" }, | |
{ name: "file-saver", var: "saveAs" } | |
]); | |
//require(["ascii-data-table"]); | |
// or, u can name the variables w/e u want | |
// require([{ name: "ascii-data-table", var: "txtTable" }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment