Skip to content

Commit

Permalink
fix(config): resolve build options with fallback (#10645)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 26, 2022
1 parent bb95467 commit f7021e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 16 additions & 8 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { ensureWatchPlugin } from './plugins/ensureWatch'
import { ESBUILD_MODULES_TARGET, VERSION } from './constants'
import { resolveChokidarOptions } from './watch'
import { completeSystemWrapPlugin } from './plugins/completeSystemWrap'
import { mergeConfig } from './publicUtils'

export interface BuildOptions {
/**
Expand Down Expand Up @@ -276,7 +277,6 @@ export interface ResolvedBuildOptions

export function resolveBuildOptions(
raw: BuildOptions | undefined,
isBuild: boolean,
logger: Logger
): ResolvedBuildOptions {
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload
Expand All @@ -301,13 +301,11 @@ export function resolveBuildOptions(
polyfill: true
}

const resolved: ResolvedBuildOptions = {
target: 'modules',
const defaultBuildOptions: BuildOptions = {
outDir: 'dist',
assetsDir: 'assets',
assetsInlineLimit: 4096,
cssCodeSplit: !raw?.lib,
cssTarget: false,
sourcemap: false,
rollupOptions: {},
minify: raw?.ssr ? false : 'esbuild',
Expand All @@ -321,17 +319,27 @@ export function resolveBuildOptions(
ssrManifest: false,
reportCompressedSize: true,
chunkSizeWarningLimit: 500,
watch: null,
...raw,
watch: null
}

const userBuildOptions = raw
? mergeConfig(defaultBuildOptions, raw)
: defaultBuildOptions

// @ts-expect-error Fallback options instead of merging
const resolved: ResolvedBuildOptions = {
target: 'modules',
cssTarget: false,
...userBuildOptions,
commonjsOptions: {
include: [/node_modules/],
extensions: ['.js', '.cjs'],
...raw?.commonjsOptions
...userBuildOptions.commonjsOptions
},
dynamicImportVarsOptions: {
warnOnError: true,
exclude: [/node_modules/],
...raw?.dynamicImportVarsOptions
...userBuildOptions.dynamicImportVarsOptions
},
// Resolve to false | object
modulePreload:
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,7 @@ export async function resolveConfig(
: './'
: resolveBaseUrl(config.base, isBuild, logger) ?? '/'

const resolvedBuildOptions = resolveBuildOptions(
config.build,
isBuild,
logger
)
const resolvedBuildOptions = resolveBuildOptions(config.build, logger)

// resolve cache directory
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true })
Expand Down

0 comments on commit f7021e3

Please sign in to comment.