feat: split options entrypoint chunks to limit file size under 4mb (#459)
All checks were successful
Build and Deploy / build-and-deploy (push) Has been skipped

This commit is contained in:
Honwhy Wang 2024-12-08 15:30:16 +08:00 committed by GitHub
parent 57829696dd
commit ec7a46f4da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,9 @@ import {
defineWxtModule, defineWxtModule,
} from 'wxt/modules' } from 'wxt/modules'
interface FakeRollupOptions {
manualChunks: (id: string) => string | undefined
}
export default defineWxtModule({ export default defineWxtModule({
async setup(wxt) { async setup(wxt) {
wxt.config.alias[`/src/main.ts`] = `./src/main.ts` wxt.config.alias[`/src/main.ts`] = `./src/main.ts`
@ -23,7 +26,22 @@ export default defineWxtModule({
skipped: false, 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, () => ({ addViteConfig(wxt, () => ({
plugins: [ plugins: [
htmlScriptToVirtual(wxt.config, () => wxt.server), htmlScriptToVirtual(wxt.config, () => wxt.server),