@@ -3,19 +3,26 @@ import type { UnocssPluginContext } from '@unocss/core'
33import { applyTransformers } from '../../shared-integration/src/transformers'
44
55export function createTransformerPlugins ( ctx : UnocssPluginContext ) : Plugin [ ] {
6- const enforces = [ 'default' , 'pre' , 'post' ] as const
7- return enforces . map ( ( enforce ) : Plugin => ( {
8- name : `unocss:transformers: ${ enforce } ` ,
9- enforce : enforce === 'default' ? undefined : enforce ,
10- transform ( code , id ) {
11- return applyTransformers ( ctx , code , id , enforce )
12- } ,
13- transformIndexHtml : {
14- order : enforce === 'default' ? undefined : enforce ,
15- handler ( code ) {
16- return applyTransformers ( ctx , code , 'index.html' , enforce )
17- . then ( t => t ?. code )
6+ const orders = [ 'default' , 'pre' , 'post' ] as const
7+ return orders . map ( ( _order ) : Plugin => {
8+ const order = _order === 'default' ? undefined : _order
9+ const htmlHandler = ( code : string ) => {
10+ return applyTransformers ( ctx , code , 'index.html' , order )
11+ . then ( t => t ?. code )
12+ }
13+ return {
14+ name : `unocss:transformers: ${ order } ` ,
15+ enforce : order ,
16+ transform ( code , id ) {
17+ return applyTransformers ( ctx , code , id , order )
1818 } ,
19- } ,
20- } ) )
19+ transformIndexHtml : {
20+ order,
21+ handler : htmlHandler ,
22+ // Compatibility with Legacy Vite
23+ enforce : order ,
24+ transform : htmlHandler ,
25+ } ,
26+ } satisfies Plugin
27+ } )
2128}
0 commit comments