Skip to content
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
9 changes: 3 additions & 6 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path'
import { pathToFileURL } from 'node:url'
import { promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import { builtinModules, createRequire } from 'node:module'
import { createRequire } from 'node:module'
import colors from 'picocolors'
import type { Alias, AliasOptions } from 'dep-types/alias'
import { build } from 'esbuild'
Expand Down Expand Up @@ -621,7 +621,7 @@ export const configDefaults = Object.freeze({
dedupe: [],
/** @experimental */
noExternal: [],
// external
external: [],
preserveSymlinks: false,
alias: [],
},
Expand Down Expand Up @@ -882,10 +882,7 @@ function resolveEnvironmentResolveOptions(
consumer === 'client' || isSsrTargetWebworkerEnvironment
? DEFAULT_CLIENT_CONDITIONS
: DEFAULT_SERVER_CONDITIONS.filter((c) => c !== 'browser'),
external:
consumer === 'server' && !isSsrTargetWebworkerEnvironment
? builtinModules
: [],
enableBuiltinNoExternalCheck: !!isSsrTargetWebworkerEnvironment,
},
resolve ?? {},
)
Expand Down
12 changes: 10 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface EnvironmentResolveOptions {
* @experimental
*/
external?: string[] | true
/**
* @internal
*/
enableBuiltinNoExternalCheck?: boolean
}

export interface ResolveOptions extends EnvironmentResolveOptions {
Expand Down Expand Up @@ -169,8 +173,11 @@ interface ResolvePluginOptions {
}

export interface InternalResolveOptions
extends Required<ResolveOptions>,
ResolvePluginOptions {}
extends Required<Omit<ResolveOptions, 'enableBuiltinNoExternalCheck'>>,
ResolvePluginOptions {
/** @internal this is always optional for backward compat */
enableBuiltinNoExternalCheck?: boolean
}

// Defined ResolveOptions are used to overwrite the values for all environments
// It is used when creating custom resolvers (for CSS, scanning, etc)
Expand Down Expand Up @@ -420,6 +427,7 @@ export function resolvePlugin(
if (isBuiltin(id)) {
if (currentEnvironmentOptions.consumer === 'server') {
if (
options.enableBuiltinNoExternalCheck &&
options.noExternal === true &&
// if both noExternal and external are true, noExternal will take the higher priority and bundle it.
// only if the id is explicitly listed in external, we will externalize it and skip this error.
Expand Down