Skip to content

Commit

Permalink
feat(resolve): auto externalize node builtins for noExternal: true
Browse files Browse the repository at this point in the history
…in node (#16019)
  • Loading branch information
bluwy committed Mar 12, 2024
1 parent 17d71ec commit 1cc88c1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/config/ssr-options.md
Expand Up @@ -18,7 +18,7 @@ Note that the explicitly listed dependencies (using `string[]` type) will always

Prevent listed dependencies from being externalized for SSR, which they will get bundled in build. By default, only linked dependencies are not externalized (for HMR). If you prefer to externalize the linked dependency, you can pass its name to the `ssr.external` option.

If `true`, no dependencies are externalized. However, dependencies explicitly listed in `ssr.external` (using `string[]` type) can take priority and still be externalized.
If `true`, no dependencies are externalized. However, dependencies explicitly listed in `ssr.external` (using `string[]` type) can take priority and still be externalized. If `ssr.target: 'node'` is set, Node.js built-ins will also be externalized by default.

Note that if both `ssr.noExternal: true` and `ssr.external: true` are configured, `ssr.noExternal` takes priority and no dependencies are externalized.

Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -402,6 +402,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
if (isBuiltin(id)) {
if (ssr) {
if (
targetWeb &&
ssrNoExternal === 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

0 comments on commit 1cc88c1

Please sign in to comment.