Skip to content

Commit

Permalink
fix(plugin-legacy): avoid esbuild transform on legacy chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 7, 2021
1 parent b72db4e commit 7734105
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/plugin-legacy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ function viteLegacyPlugin(options = {}) {
legacyPolyfills,
bundle,
facadeToLegacyPolyfillMap,
config.build.minify
// force using terser for legacy polyfill minification, since esbuild
// isn't legacy-safe
config.build.minify ? 'terser' : false
)
}
}
Expand Down Expand Up @@ -166,6 +168,10 @@ function viteLegacyPlugin(options = {}) {
return
}

// @ts-ignore avoid esbuild transform on legacy chunks since it produces
// legacy-unsafe code - e.g. rewriting object properties into shorthands
opts.__vite_skip_esbuild__ = true

const needPolyfills =
options.polyfills !== false && !Array.isArray(options.polyfills)

Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ export function esbuildPlugin(options: ESBuildOptions = {}): Plugin {
export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
return {
name: 'vite:esbuild-transpile',
async renderChunk(code, chunk) {
async renderChunk(code, chunk, opts) {
// @ts-ignore injected by @vitejs/plugin-legacy
if (opts.__vite_skip_esbuild__) {
return null
}

const target = config.build.target
const minify = config.build.minify === 'esbuild'
if (!target && !minify) {
Expand Down

0 comments on commit 7734105

Please sign in to comment.