Skip to content

Commit 7ba0c9f

Browse files
authored
refactor(legacy): build polyfill chunk (#9639)
1 parent bc4a627 commit 7ba0c9f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

packages/plugin-legacy/src/index.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,6 @@ async function buildPolyfillChunk(
633633
plugins: [polyfillsPlugin(imports, excludeSystemJS)],
634634
build: {
635635
write: false,
636-
// if a value above 'es5' is set, esbuild injects helper functions which uses es2015 features
637-
target: 'es5',
638636
minify,
639637
assetsDir,
640638
rollupOptions: {
@@ -646,6 +644,18 @@ async function buildPolyfillChunk(
646644
entryFileNames: rollupOutputOptions.entryFileNames
647645
}
648646
}
647+
},
648+
// Don't run esbuild for transpilation or minification
649+
// because we don't want to transpile code.
650+
esbuild: false,
651+
optimizeDeps: {
652+
esbuildOptions: {
653+
// If a value above 'es5' is set, esbuild injects helper functions which uses es2015 features.
654+
// This limits the input code not to include es2015+ codes.
655+
// But core-js is the only dependency which includes commonjs code
656+
// and core-js doesn't include es2015+ codes.
657+
target: 'es5'
658+
}
649659
}
650660
})
651661
const _polyfillChunk = Array.isArray(res) ? res[0] : res
@@ -685,21 +695,6 @@ function polyfillsPlugin(
685695
(excludeSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
686696
)
687697
}
688-
},
689-
renderChunk(_, __, opts) {
690-
// systemjs includes code that can't be minified down to es5 by esbuild
691-
if (!excludeSystemJS) {
692-
// @ts-ignore avoid esbuild transform on legacy chunks since it produces
693-
// legacy-unsafe code - e.g. rewriting object properties into shorthands
694-
opts.__vite_skip_esbuild__ = true
695-
696-
// @ts-ignore force terser for legacy chunks. This only takes effect if
697-
// minification isn't disabled, because that leaves out the terser plugin
698-
// entirely.
699-
opts.__vite_force_terser__ = true
700-
}
701-
702-
return null
703698
}
704699
}
705700
}

0 commit comments

Comments
 (0)