Skip to content

Commit 337b197

Browse files
authoredMay 29, 2022
feat: add ssr.format to force esm output for ssr (#6812)
1 parent 79d5ce1 commit 337b197

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎packages/vite/src/node/build.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ async function doBuild(
342342
const config = await resolveConfig(inlineConfig, 'build', 'production')
343343
const options = config.build
344344
const ssr = !!options.ssr
345+
const esm = config.ssr?.format === 'es' || !ssr
345346
const libOptions = options.lib
346347

347348
config.logger.info(
@@ -433,8 +434,8 @@ async function doBuild(
433434
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
434435
return {
435436
dir: outDir,
436-
format: ssr ? 'cjs' : 'es',
437-
exports: ssr ? 'named' : 'auto',
437+
format: esm ? 'es' : 'cjs',
438+
exports: esm ? 'auto' : 'named',
438439
sourcemap: options.sourcemap,
439440
name: libOptions ? libOptions.name : undefined,
440441
generatedCode: 'es2015',

‎packages/vite/src/node/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ export interface SSROptions {
239239
* Default: 'node'
240240
*/
241241
target?: SSRTarget
242+
243+
/**
244+
* Define the module format for the ssr build.
245+
* Default: 'cjs'
246+
*/
247+
format?: 'es' | 'cjs'
242248
}
243249

244250
export interface ResolveWorkerOptions {

0 commit comments

Comments
 (0)
Please sign in to comment.