Created
July 17, 2018 23:12
-
-
Save adamisntdead/c04a267373e6febbfd97f1152e58ba50 to your computer and use it in GitHub Desktop.
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
function pack(modules) { | |
const modulesSource = modules.map(module => | |
`${module.id}: { | |
factory: (module, require) => { | |
${module.source} | |
}, | |
map: ${JSON.stringify(module.map)} | |
}` | |
).join() | |
return `(modules => { | |
const require = id => { | |
const { factory, map } = modules[id] | |
const localRequire = name => require(map[name]) | |
const module = { exports: {} } | |
factory(module, localRequire) | |
return module.exports | |
} | |
require(0) | |
})({ ${modulesSource} })` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment