Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 14, 2024
1 parent 7f94c03 commit 9a600fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
25 changes: 22 additions & 3 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,31 @@ export interface BuilderOptions {
) => Promise<void>
}

export interface BuilderInlineConfig extends Omit<InlineConfig, 'plugins'> {
plugins?: () => Plugin[]
}

export async function createViteBuilder(
builderOptions: BuilderOptions = {},
defaultInlineConfig: InlineConfig = {},
defaultInlineConfig: BuilderInlineConfig = {},
): Promise<ViteBuilder> {
// Plugins passed to the Builder inline config needs to be created
// from a factory to ensure each build has their own instances
const getDefaultInlineConfig = (): InlineConfig => {
const { plugins } = defaultInlineConfig
return plugins
? {
...defaultInlineConfig,
plugins: plugins(),
}
: (defaultInlineConfig as InlineConfig)
}

// We need to resolve a default config to get the plugins and be able
// to run the configureBuildEnvironments hooks. Maybe we should expose
// this hook as a builder option instead to avoid this.
const defaultConfig = await resolveConfig(
defaultInlineConfig,
getDefaultInlineConfig(),
'build',
'production',
'production',
Expand Down Expand Up @@ -1349,7 +1368,7 @@ export async function createViteBuilder(
// and to process a single bundle at a time (contrary to dev mode where
// plugins are built to handle multiple environments concurrently).

let userConfig = defaultInlineConfig
let userConfig = getDefaultInlineConfig()
const inlineConfigEnvironmentOverrides =
defaultInlineConfig.environment?.[environment.id]
if (inlineConfigEnvironmentOverrides) {
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export interface SharedEnvironmentConfig {
resolve?: ResolveOptions & { alias?: AliasOptions }
/**
* Dep optimization options
* These options are only used during dev. It should better be in the
* dev options but there isn't a strong enough reason to move it there
* at this point.
*/
optimizeDeps?: DepOptimizationOptions
}
Expand Down Expand Up @@ -337,8 +340,8 @@ export interface UserConfig extends EnvironmentConfig {
appType?: AppType
/**
* SSR specific options
* Some of the options previously under `ssr` (like resolve.conditions) are deprecated
* and moved to environment: { ssr: { ... } }
* We could make SSROptions be a EnvironmentConfig if we can abstract
* external/noExternal for environments in general.
*/
ssr?: SSROptions
/**
Expand Down

0 comments on commit 9a600fe

Please sign in to comment.