Skip to content

Commit

Permalink
fix(plugin-legacy): skip in SSR build (vitejs#4536)
Browse files Browse the repository at this point in the history
  • Loading branch information
andylizi authored and aleclarson committed Nov 8, 2021
1 parent 9cf100b commit b6933d9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/plugin-legacy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function viteLegacyPlugin(options = {}) {
apply: 'build',

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

async generateBundle(opts, bundle) {
if (config.build.ssr) {
return
}

if (!isLegacyBundle(bundle, opts)) {
if (!modernPolyfills.size) {
return
Expand Down Expand Up @@ -170,7 +174,7 @@ function viteLegacyPlugin(options = {}) {
}
config = _config

if (!genLegacy) {
if (!genLegacy || config.build.ssr) {
return
}

Expand Down Expand Up @@ -226,6 +230,10 @@ function viteLegacyPlugin(options = {}) {
},

renderChunk(raw, chunk, opts) {
if (config.build.ssr) {
return
}

if (!isLegacyChunk(chunk, opts)) {
if (
options.modernPolyfills &&
Expand Down Expand Up @@ -315,6 +323,7 @@ function viteLegacyPlugin(options = {}) {
},

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

generateBundle(opts, bundle) {
if (config.build.ssr) {
return
}

if (isLegacyBundle(bundle, opts)) {
// avoid emitting duplicate assets
for (const name in bundle) {
Expand Down

0 comments on commit b6933d9

Please sign in to comment.