Skip to content

Commit

Permalink
feat: split options entrypoint chunks to limit file size under 4mb
Browse files Browse the repository at this point in the history
  • Loading branch information
honwhy committed Dec 8, 2024
1 parent c5e86ca commit 3e7523f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/modules/build-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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<string, string>
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),
Expand Down

0 comments on commit 3e7523f

Please sign in to comment.