Skip to content

Commit

Permalink
chore: use ssr.noExternal = true rather than new option
Browse files Browse the repository at this point in the history
  • Loading branch information
jplhomer committed Aug 16, 2021
1 parent 3de7bba commit f7d1c36
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
11 changes: 2 additions & 9 deletions docs/config/index.md
Expand Up @@ -741,20 +741,13 @@ SSR options may be adjusted in minor releases.

### ssr.noExternal

- **Type:** `string | RegExp | (string | RegExp)[]`
- **Type:** `string | RegExp | (string | RegExp)[] | true`

Prevent listed dependencies from being externalized for SSR.
Prevent listed dependencies from being externalized for SSR. If `true`, no dependencies are externalized.

### ssr.target

- **Type:** `'node' | 'webworker'`
- **Default:** `node`

Build target for the SSR server.

### ssr.bundleAll

- **Type:** `boolean`
- **Default:** `false`

Bundles all dependencies into a single JavaScript file.
2 changes: 1 addition & 1 deletion docs/guide/ssr.md
Expand Up @@ -254,7 +254,7 @@ The default target for the SSR build is a node environment, but you can also run
## SSR Bundle
In some cases like `webworker` runtimes, you might want to bundle your SSR build into a single JavaScript file. You can enable this behavior by setting `ssr.bundleAll` to `true`. This will do two things:
In some cases like `webworker` runtimes, you might want to bundle your SSR build into a single JavaScript file. You can enable this behavior by setting `ssr.noExternal` to `true`. This will do two things:
- Treat all dependencies as `noExternal`
- Throw an error if any Node.js built-ins are imported
2 changes: 1 addition & 1 deletion packages/playground/ssr-webworker/vite.config.js
Expand Up @@ -7,6 +7,6 @@ module.exports = {
},
ssr: {
target: 'webworker',
bundleAll: true
noExternal: true
}
}
3 changes: 1 addition & 2 deletions packages/vite/src/node/config.ts
Expand Up @@ -187,14 +187,13 @@ export type SSRTarget = 'node' | 'webworker'

export interface SSROptions {
external?: string[]
noExternal?: string | RegExp | (string | RegExp)[]
noExternal?: string | RegExp | (string | RegExp)[] | true
/**
* Define the target for the ssr build. The browser field in package.json
* is ignored for node but used if webworker is the target
* Default: 'node'
*/
target?: SSRTarget
bundleAll?: boolean
}

export interface InlineConfig extends UserConfig {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -78,7 +78,7 @@ export function resolvePlugin(baseOptions: InternalResolveOptions): Plugin {
}
let server: ViteDevServer | undefined

const { target: ssrTarget } = ssrConfig ?? {}
const { target: ssrTarget, noExternal: ssrNoExternal } = ssrConfig ?? {}

return {
name: 'vite:resolve',
Expand Down Expand Up @@ -226,15 +226,15 @@ export function resolvePlugin(baseOptions: InternalResolveOptions): Plugin {
// externalize if building for SSR, otherwise redirect to empty module
if (isBuiltin(id)) {
if (ssr) {
if (ssrConfig?.bundleAll) {
if (ssrNoExternal === true) {
let message = `Cannot bundle Node.js built-in "${id}"`
if (importer) {
message += ` imported from "${path.relative(
process.cwd(),
importer
)}"`
}
message += `. Consider disabling ssr.bundleAll or remove the built-in dependency.`
message += `. Consider disabling ssr.noExternal or remove the built-in dependency.`
this.error(message)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrExternal.ts
Expand Up @@ -18,7 +18,7 @@ export function resolveSSRExternal(
ssrExternals: Set<string> = new Set(),
seen: Set<string> = new Set()
): string[] {
if (config.ssr?.bundleAll) {
if (config.ssr?.noExternal === true) {
return []
}

Expand Down

0 comments on commit f7d1c36

Please sign in to comment.