Skip to content

Commit 1f068fc

Browse files
authored
fix(plugin-legacy): skip in SSR build (#4536)
1 parent 8d956f6 commit 1f068fc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/plugin-legacy/index.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function viteLegacyPlugin(options = {}) {
9797
apply: 'build',
9898

9999
configResolved(config) {
100-
if (config.build.minify === 'esbuild') {
100+
if (!config.build.ssr && config.build.minify === 'esbuild') {
101101
throw new Error(
102102
`Can't use esbuild as the minifier when targeting legacy browsers ` +
103103
`because esbuild minification is not legacy safe.`
@@ -106,6 +106,10 @@ function viteLegacyPlugin(options = {}) {
106106
},
107107

108108
async generateBundle(opts, bundle) {
109+
if (config.build.ssr) {
110+
return
111+
}
112+
109113
if (!isLegacyBundle(bundle, opts)) {
110114
if (!modernPolyfills.size) {
111115
return
@@ -170,7 +174,7 @@ function viteLegacyPlugin(options = {}) {
170174
}
171175
config = _config
172176

173-
if (!genLegacy) {
177+
if (!genLegacy || config.build.ssr) {
174178
return
175179
}
176180

@@ -226,6 +230,10 @@ function viteLegacyPlugin(options = {}) {
226230
},
227231

228232
renderChunk(raw, chunk, opts) {
233+
if (config.build.ssr) {
234+
return
235+
}
236+
229237
if (!isLegacyChunk(chunk, opts)) {
230238
if (
231239
options.modernPolyfills &&
@@ -315,6 +323,7 @@ function viteLegacyPlugin(options = {}) {
315323
},
316324

317325
transformIndexHtml(html, { chunk }) {
326+
if (config.build.ssr) return
318327
if (!chunk) return
319328
if (chunk.fileName.includes('-legacy')) {
320329
// The legacy bundle is built first, and its index.html isn't actually
@@ -420,6 +429,10 @@ function viteLegacyPlugin(options = {}) {
420429
},
421430

422431
generateBundle(opts, bundle) {
432+
if (config.build.ssr) {
433+
return
434+
}
435+
423436
if (isLegacyBundle(bundle, opts)) {
424437
// avoid emitting duplicate assets
425438
for (const name in bundle) {

0 commit comments

Comments
 (0)