From ec7a46f4dab97a1ec459b470a7da6674b18c16f1 Mon Sep 17 00:00:00 2001 From: Honwhy Wang Date: Sun, 8 Dec 2024 15:30:16 +0800 Subject: [PATCH] feat: split options entrypoint chunks to limit file size under 4mb (#459) --- src/modules/build-extension.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/build-extension.ts b/src/modules/build-extension.ts index ca3b2c0..aa40044 100644 --- a/src/modules/build-extension.ts +++ b/src/modules/build-extension.ts @@ -9,6 +9,9 @@ import { defineWxtModule, } from 'wxt/modules' +interface FakeRollupOptions { + manualChunks: (id: string) => string | undefined +} export default defineWxtModule({ async setup(wxt) { wxt.config.alias[`/src/main.ts`] = `./src/main.ts` @@ -23,7 +26,22 @@ export default defineWxtModule({ skipped: false, }]) }) - + wxt.hook(`vite:build:extendConfig`, (_, config) => { + if (config.build?.rollupOptions?.input && config.build?.rollupOptions?.input) { + const input = config.build?.rollupOptions.input as Record + if (input.options) { + const output = config.build?.rollupOptions.output as FakeRollupOptions + output.manualChunks = (id) => { + if (id.includes(`prettier`)) { + return `prettier-chunk` + } + if (id.includes(`highlight.js`)) { + return `highlight-chunk` + } + } + } + } + }) addViteConfig(wxt, () => ({ plugins: [ htmlScriptToVirtual(wxt.config, () => wxt.server),