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
*/
configureVite?: (
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.

Please help add comments for each options.

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.

Done

config: InlineConfig,
isServer: boolean,
isBuild: boolean,
) => InlineConfig | void
}
Loading