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

fix(config): resolve build options with fallback #10645

Merged
merged 2 commits into from
Oct 26, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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