Skip to content

Commit

Permalink
feat: add ssr.format to force esm output for ssr (#6812)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 29, 2022
1 parent 79d5ce1 commit 337b197
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/vite/src/node/build.ts
Expand Up @@ -342,6 +342,7 @@ async function doBuild(
const config = await resolveConfig(inlineConfig, 'build', 'production')
const options = config.build
const ssr = !!options.ssr
const esm = config.ssr?.format === 'es' || !ssr
const libOptions = options.lib

config.logger.info(
Expand Down Expand Up @@ -433,8 +434,8 @@ async function doBuild(
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
return {
dir: outDir,
format: ssr ? 'cjs' : 'es',
exports: ssr ? 'named' : 'auto',
format: esm ? 'es' : 'cjs',
exports: esm ? 'auto' : 'named',
sourcemap: options.sourcemap,
name: libOptions ? libOptions.name : undefined,
generatedCode: 'es2015',
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/config.ts
Expand Up @@ -239,6 +239,12 @@ export interface SSROptions {
* Default: 'node'
*/
target?: SSRTarget

/**
* Define the module format for the ssr build.
* Default: 'cjs'
*/
format?: 'es' | 'cjs'
}

export interface ResolveWorkerOptions {
Expand Down

0 comments on commit 337b197

Please sign in to comment.