Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate splitVendorChunkPlugin #16274

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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