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

fix(plugin-legacy): skip in SSR build #4536

Merged
merged 1 commit into from
Sep 6, 2021
Merged
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
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ideally we could have some feature extends apply, like

apply: 'client-build' | 'ssr-build'

but in that case, maybe a function would be more flexible:

apply(config) {
  return config.command === 'build' && !config.build.ssr
}

🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm voting for a function; I can see other scenarios where an apply function would be helpful.


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) {
andylizi marked this conversation as resolved.
Show resolved Hide resolved
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