Skip to content

Commit 4646e9f

Browse files
patak-devbluwy
andauthoredJul 14, 2023
chore: warning about ssr cjs format removal (#13827)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
1 parent b6155a1 commit 4646e9f

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed
 

‎docs/config/ssr-options.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Build target for the SSR server.
2424
## ssr.format
2525

2626
- **Experimental**
27+
- **Deprecated** Only ESM output will be supported in Vite 5.
2728
- **Type:** `'esm' | 'cjs'`
2829
- **Default:** `esm`
2930

‎docs/guide/ssr.md

+4
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,7 @@ Use a post hook so that your SSR middleware runs _after_ Vite's middlewares.
270270
## SSR Format
271271
272272
By default, Vite generates the SSR bundle in ESM. There is experimental support for configuring `ssr.format`, but it isn't recommended. Future efforts around SSR development will be based on ESM, and CommonJS remains available for backward compatibility. If using ESM for SSR isn't possible in your project, you can set `legacy.buildSsrCjsExternalHeuristics: true` to generate a CJS bundle using the same [externalization heuristics of Vite v2](https://v2.vitejs.dev/guide/ssr.html#ssr-externals).
273+
274+
:::warning Warning
275+
Experimental `legacy.buildSsrCjsExternalHeuristics` and `ssr.format: 'cjs'` are going to be removed in Vite 5. Find more information and give feedback [in this discussion](https://github.com/vitejs/vite/discussions/13816).
276+
:::

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

+13
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,19 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter
837837
}
838838
}
839839

840+
// Warn about removal of experimental features
841+
if (
842+
config.legacy?.buildSsrCjsExternalHeuristics ||
843+
config.ssr?.format === 'cjs'
844+
) {
845+
resolved.logger.warn(
846+
colors.yellow(`
847+
(!) Experimental legacy.buildSsrCjsExternalHeuristics and ssr.format: 'cjs' are going to be removed in Vite 5.
848+
Find more information and give feedback at https://github.com/vitejs/vite/discussions/13816.
849+
`),
850+
)
851+
}
852+
840853
return resolved
841854
}
842855

‎packages/vite/src/node/ssr/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface SSROptions {
2020
* left marked as experimental to give users more time to update to ESM. CJS builds requires
2121
* complex externalization heuristics that aren't present in the ESM format.
2222
* @experimental
23+
* @deprecated
2324
* @default 'esm'
2425
*/
2526
format?: SSRFormat

0 commit comments

Comments
 (0)
Please sign in to comment.