feat: webpack hook load all chunks

This commit is contained in:
Xmader 2020-11-19 00:51:09 -05:00
parent eaff7b123c
commit f8221a0f50
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4

View file

@ -122,4 +122,23 @@ export const webpackContext = new Promise<any>((resolve) => {
})
})
const PACK_ID_REG = /\+(\{.*?"\})\[\w\]\+/
export const loadAllPacks = () => {
return webpackContext.then((ctx) => {
try {
const fn = ctx.e.toString()
const packsData = fn.match(PACK_ID_REG)[1] as string
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
const packs = Function(`return (${packsData})`)() as { [id: string]: string }
Object.keys(packs).forEach((id) => {
ctx.e(id)
})
} catch (err) {
console.error(err)
}
})
}
export default webpackHook