From f8221a0f50a27bd5adedb83fc63520c4017e59de Mon Sep 17 00:00:00 2001 From: Xmader Date: Thu, 19 Nov 2020 00:51:09 -0500 Subject: [PATCH] feat: webpack hook load all chunks --- src/webpack-hook.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/webpack-hook.ts b/src/webpack-hook.ts index 5db01ab..e279ac1 100644 --- a/src/webpack-hook.ts +++ b/src/webpack-hook.ts @@ -122,4 +122,23 @@ export const webpackContext = new Promise((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