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(build): apply resolve.external/noExternal to server environments #18495

Merged
merged 1 commit into from
Oct 28, 2024
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
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function resolvePlugins(
asSrc: true,
fsUtils: getFsUtils(config),
optimizeDeps: true,
externalize: isBuild && !!config.build.ssr, // TODO: should we do this for all environments?
externalize: true,
},
config.environments,
),
Expand Down
17 changes: 13 additions & 4 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ export interface EnvironmentResolveOptions {
*/
extensions?: string[]
dedupe?: string[]
// TODO: better abstraction that works for the client environment too?
/**
* external/noExternal logic, this only works for certain environments
* Previously this was ssr.external/ssr.noExternal
* TODO: better abstraction that works for the client environment too?
* Prevent listed dependencies from being externalized and will get bundled in build.
* Only works in server environments for now. Previously this was `ssr.noExternal`.
* @experimental
*/
noExternal?: string | RegExp | (string | RegExp)[] | true
/**
* Externalize the given dependencies and their transitive dependencies.
* Only works in server environments for now. Previously this was `ssr.external`.
* @experimental
*/
external?: string[] | true
}

Expand Down Expand Up @@ -135,7 +141,8 @@ interface ResolvePluginOptions {
optimizeDeps?: boolean

/**
* externalize using external/noExternal, defaults to false // TODO: Review default
* Externalize using `resolve.external` and `resolve.noExternal` when running a build in
* a server environment. Defaults to false (only for createResolver)
* @internal
*/
externalize?: boolean
Expand Down Expand Up @@ -398,6 +405,8 @@ export function resolvePlugin(
if (bareImportRE.test(id)) {
const external =
options.externalize &&
options.isBuild &&
currentEnvironmentOptions.consumer === 'server' &&
shouldExternalize(this.environment, id, importer)
if (
!external &&
Expand Down