Skip to content

Commit

Permalink
fix: apply resolve.external/noExternal to server environments
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 28, 2024
1 parent 472afbd commit dee60ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit dee60ba

Please sign in to comment.