Skip to content

Commit

Permalink
fix: account for rollupOptions.output array
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 17, 2022
1 parent 0a06f13 commit 2306dad
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/vite/src/node/plugins/splitVendorChunk.ts
@@ -1,3 +1,4 @@
import type { UserConfig } from '../../node'
import type { Plugin } from '../plugin'
import type { OutputOptions, GetManualChunk, GetModuleInfo } from 'rollup'
import { isCSSRequest } from './css'
Expand Down Expand Up @@ -72,24 +73,37 @@ function staticImportedByEntry(
}

export function splitVendorChunkPlugin(): Plugin {
const cache = new SplitVendorChunkCache()
const caches: SplitVendorChunkCache[] = []
function createSplitVendorChunk(output: OutputOptions, config: UserConfig) {
const cache = new SplitVendorChunkCache()
caches.push(cache)
const build = config.build ?? {}
const format = output?.format
if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
return splitVendorChunk({ cache })
}
}
return {
name: 'vite:split-vendor-chunk',
config(config) {
const build = config.build ?? {}
const format = (build.rollupOptions?.output as OutputOptions)?.format
if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
let outputs = config?.build?.rollupOptions?.output
if (outputs) {
outputs = Array.isArray(outputs) ? outputs : [outputs]
for (const output of outputs) {
output.manualChunks = createSplitVendorChunk(output, config)
}
} else {
return {
build: {
rollupOptions: {
manualChunks: splitVendorChunk({ cache })
manualChunks: createSplitVendorChunk({}, config)
}
}
}
}
},
buildStart() {
cache.reset()
caches.forEach((cache) => cache.reset())
}
}
}

0 comments on commit 2306dad

Please sign in to comment.