Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/bundler-vite/src/resolveViteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export const resolveViteConfig = ({
options: ViteBundlerOptions
isBuild: boolean
isServer: boolean
}): InlineConfig =>
mergeConfig(
}): InlineConfig => {
// generate base vite config
let viteConfig = mergeConfig(
{
clearScreen: false,
configFile: false,
Expand All @@ -43,3 +44,18 @@ export const resolveViteConfig = ({
// some vite options would not take effect inside a plugin, so we still need to merge them here in addition to userConfigPlugin
options.viteOptions ?? {},
)

// allow modifying vite config via `configureVite`
const configureViteResult = options.configureVite?.(
viteConfig,
isServer,
isBuild,
)

// if `configureVite` returns a configuration object, use vite's mergeConfig to merge it
if (configureViteResult) {
viteConfig = mergeConfig(viteConfig, configureViteResult)
}

return viteConfig
}
19 changes: 19 additions & 0 deletions packages/bundler-vite/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import type { InlineConfig } from 'vite'
* Options for bundler-vite
*/
export interface ViteBundlerOptions extends BundlerOptions {
/**
* Vite options
*/
viteOptions?: InlineConfig
/**
* Options for @vitejs/plugin-vue
*/
vuePluginOptions?: VuePluginOptions
/**
* Modify Vite config
*
* @param config - Vite config
* @param isServer - Whether it is server bundle
* @param isBuild - Whether in build mode
* @returns Vite config to be merged with the default config

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to clarify that an empty return is also valid.

@Mister-Hope Mister-Hope Jun 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1714 part 3. We do not allow "Vite config to be merged with the default config" anymore in that.

This msg will be updated to a new one after that is merged.

In short, 1714 covers all things in this PR, just because you do not like heavy refactors in other contributors' PRs rather than you.

I don't hink any futher update is needed, this msg will be removed anyway after the whole improvement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short, you should review #1714 first, this PR just behaves like a refactor splitting.

If you want, you can merge with rebase for that, and this will no longer needed.

Please leave your futher opinion there.

*/
configureVite?: (
Comment thread
meteorlxy marked this conversation as resolved.
config: InlineConfig,
isServer: boolean,
isBuild: boolean,
) => InlineConfig | void
}
Loading