Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ssr.format to force esm output for ssr #6812

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,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 @@ -464,8 +465,8 @@ async function doBuild(

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,
entryFileNames: ssr
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,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