@@ -487,8 +487,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
487
487
// )
488
488
// }
489
489
const polyfillsDiscovered = {
490
- modern : new Set ( ) ,
491
- legacy : new Set ( ) ,
490
+ modern : new Set < string > ( ) ,
491
+ legacy : new Set < string > ( ) ,
492
492
}
493
493
494
494
if ( ! isLegacyChunk ( chunk , opts ) ) {
@@ -557,12 +557,23 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
557
557
// transform the legacy chunk with @babel /preset-env
558
558
const sourceMaps = ! ! config . build . sourcemap
559
559
const babel = await loadBabel ( )
560
- const systemJsPlugins = [
561
- // @ts -ignore
562
- ( await import ( '@babel/plugin-transform-dynamic-import' ) ) . default ,
563
- // @ts -ignore
564
- ( await import ( '@babel/plugin-transform-modules-systemjs' ) ) . default ,
565
- ]
560
+
561
+ // need to transform into systemjs separately from other plugins
562
+ // for preset-env polyfill detection and removal
563
+ // TODO: use transformFromAst to avoid multiple parse
564
+ const resultSystem = babel . transform ( raw , {
565
+ babelrc : false ,
566
+ configFile : false ,
567
+ // TODO: source map
568
+ plugins : [
569
+ // @ts -ignore
570
+ ( await import ( '@babel/plugin-transform-dynamic-import' ) ) . default ,
571
+ // @ts -ignore
572
+ ( await import ( '@babel/plugin-transform-modules-systemjs' ) ) . default ,
573
+ ] ,
574
+ } )
575
+ raw = resultSystem ?. code !
576
+
566
577
const result = babel . transform ( raw , {
567
578
babelrc : false ,
568
579
configFile : false ,
@@ -575,7 +586,6 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
575
586
[
576
587
( ) => ( {
577
588
plugins : [
578
- ...systemJsPlugins ,
579
589
recordAndRemovePolyfillBabelPlugin ( polyfillsDiscovered . legacy ) ,
580
590
replaceLegacyEnvBabelPlugin ( ) ,
581
591
wrapIIFEBabelPlugin ( ) ,
0 commit comments