Skip to content

Commit

Permalink
feat: allow speicfying ssr entry directly via build.ssr option
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 25, 2021
1 parent dae6b52 commit 45d8bf4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/build.ts
Expand Up @@ -155,7 +155,7 @@ export interface BuildOptions {
* Produce SSR oriented build. Note this requires specifying SSR entry via
* `rollupOptions.input`.
*/
ssr?: boolean
ssr?: boolean | string
/**
* Generate SSR manifest for determining style links and asset preload
* directives in production.
Expand Down Expand Up @@ -291,6 +291,8 @@ async function doBuild(
const resolve = (p: string) => path.resolve(config.root, p)
const input = libOptions
? resolve(libOptions.entry)
: typeof options.ssr === 'string'
? resolve(options.ssr)
: options.rollupOptions?.input || resolve('index.html')

if (ssr && typeof input === 'string' && input.endsWith('.html')) {
Expand Down
8 changes: 0 additions & 8 deletions packages/vite/src/node/cli.ts
Expand Up @@ -134,14 +134,6 @@ cli
const { build } = await import('./build')
const buildOptions = cleanOptions(options) as BuildOptions

if (buildOptions.ssr) {
buildOptions.rollupOptions = {
...buildOptions.rollupOptions,
input: (buildOptions.ssr as any) as string
}
buildOptions.ssr = true
}

try {
await build({
root,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Expand Up @@ -41,7 +41,7 @@ export async function ssrLoadModule(
(await transformRequest(url, server, { ssr: true }))
if (!result) {
// TODO more info? is this even necessary?
throw new Error(`failed to load module for ssr: $${url}`)
throw new Error(`failed to load module for ssr: ${url}`)
}

const isExternal = (dep: string) => dep[0] !== '.' && dep[0] !== '/'
Expand Down

0 comments on commit 45d8bf4

Please sign in to comment.