@@ -577,6 +577,9 @@ async function createProjectService(
577
577
let userVariants : any
578
578
let userMode : any
579
579
let userPlugins : any
580
+ let presetModes : any [ ] = [ ]
581
+ let presetVariants : any [ ] = [ ]
582
+
580
583
let hook = new Hook ( fs . realpathSync ( state . configPath ) , ( exports ) => {
581
584
userSeperator = dlv ( exports , sepLocation )
582
585
if ( typeof userSeperator !== 'string' ) {
@@ -589,17 +592,38 @@ async function createProjectService(
589
592
`__TWSEP__${ typeof userSeperator === 'undefined' ? ':' : userSeperator } __TWSEP__`
590
593
)
591
594
exports . purge = [ ]
592
- if ( state . modules . jit && exports . mode === 'jit' ) {
595
+
596
+ let mode : any
597
+ if ( Array . isArray ( exports . presets ) ) {
598
+ for ( let preset of exports . presets ) {
599
+ if ( typeof preset . mode !== 'undefined' ) {
600
+ mode = preset . mode
601
+ }
602
+ presetModes . push ( preset . mode )
603
+ delete preset . mode
604
+ }
605
+ }
606
+ if ( typeof exports . mode !== 'undefined' ) {
607
+ mode = exports . mode
608
+ }
609
+ userMode = exports . mode
610
+ delete exports . mode
611
+
612
+ if ( state . modules . jit && mode === 'jit' ) {
593
613
state . jit = true
594
614
userVariants = exports . variants
595
615
exports . variants = [ ]
616
+
617
+ if ( Array . isArray ( exports . presets ) ) {
618
+ for ( let preset of exports . presets ) {
619
+ presetVariants . push ( preset . variants )
620
+ preset . variants = [ ]
621
+ }
622
+ }
596
623
} else {
597
624
state . jit = false
598
625
}
599
626
600
- userMode = exports . mode
601
- delete exports . mode
602
-
603
627
// inject JIT `matchUtilities` function
604
628
if ( Array . isArray ( exports . plugins ) ) {
605
629
userPlugins = exports . plugins
@@ -702,6 +726,21 @@ async function createProjectService(
702
726
config . plugins = userPlugins
703
727
}
704
728
729
+ for ( let index in presetModes ) {
730
+ if ( typeof presetModes [ index ] === 'undefined' ) {
731
+ delete config . presets [ index ] . mode
732
+ } else {
733
+ config . presets [ index ] . mode = presetModes [ index ]
734
+ }
735
+ }
736
+ for ( let index in presetVariants ) {
737
+ if ( typeof presetVariants [ index ] === 'undefined' ) {
738
+ delete config . presets [ index ] . variants
739
+ } else {
740
+ config . presets [ index ] . variants = presetVariants [ index ]
741
+ }
742
+ }
743
+
705
744
if ( state . dependencies ) {
706
745
watcher . unwatch ( state . dependencies )
707
746
}
0 commit comments