Skip to content

Commit

Permalink
chore: deprecate splitVendorChunkPlugin (#16274)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Mar 29, 2024
1 parent ffedc06 commit 45a06da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
16 changes: 1 addition & 15 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,7 @@ For example, you can specify multiple Rollup outputs with plugins that are only

## Chunking Strategy

You can configure how chunks are split using `build.rollupOptions.output.manualChunks` (see [Rollup docs](https://rollupjs.org/configuration-options/#output-manualchunks)). Until Vite 2.8, the default chunking strategy divided the chunks into `index` and `vendor`. It is a good strategy for some SPAs, but it is hard to provide a general solution for every Vite target use case. From Vite 2.9, `manualChunks` is no longer modified by default. You can continue to use the Split Vendor Chunk strategy by adding the `splitVendorChunkPlugin` in your config file:

```js
// vite.config.js
import { splitVendorChunkPlugin } from 'vite'
export default defineConfig({
plugins: [splitVendorChunkPlugin()],
})
```

This strategy is also provided as a `splitVendorChunk({ cache: SplitVendorChunkCache })` factory, in case composition with custom logic is needed. `cache.reset()` needs to be called at `buildStart` for build watch mode to work correctly in this case.

::: warning
You should use `build.rollupOptions.output.manualChunks` function form when using this plugin. If the object form is used, the plugin won't have any effect.
:::
You can configure how chunks are split using `build.rollupOptions.output.manualChunks` (see [Rollup docs](https://rollupjs.org/configuration-options/#output-manualchunks)). If you use a framework, refer to their documentation for configuring how chunks are splitted.

## Load Error Handling

Expand Down
9 changes: 9 additions & 0 deletions packages/vite/src/node/plugins/splitVendorChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const isCSSRequest = (request: string): boolean =>
// The cache needs to be reset on buildStart for watch mode to work correctly
// Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'

/**
* @deprecated use build.rollupOutput.manualChunks or framework specific configuration
*/
export class SplitVendorChunkCache {
cache: Map<string, boolean>
constructor() {
Expand All @@ -36,6 +39,9 @@ export class SplitVendorChunkCache {
}
}

/**
* @deprecated use build.rollupOutput.manualChunks or framework specific configuration
*/
export function splitVendorChunk(
options: { cache?: SplitVendorChunkCache } = {},
): GetManualChunk {
Expand Down Expand Up @@ -87,6 +93,9 @@ function staticImportedByEntry(
return someImporterIs
}

/**
* @deprecated use build.rollupOutput.manualChunks or framework specific configuration
*/
export function splitVendorChunkPlugin(): Plugin {
const caches: SplitVendorChunkCache[] = []
function createSplitVendorChunk(output: OutputOptions, config: UserConfig) {
Expand Down

0 comments on commit 45a06da

Please sign in to comment.