import type { Plugin } from 'vite' ; import { createFilter } from '@rollup/pluginutils' ; import type { UnocssPluginContext } from '../../../plugins-common' ; import { defaultExclude } from '../../../plugins-common' ; export function VueScopedPlugin ( { uno , ready } ) { let filter = createFilter ( [ /\.vue$/ ] , defaultExclude ) ; async function transformSFC ( code ) { const { css } = await uno . generate ( code ) ; if ( ! css ) return null ; return `${ code }\n<style scoped>${ css }</style>` ; } return { name : 'unocss:vue-scoped' , enforce : 'pre' , async configResolved ( ) { const { config } = await ready ; filter = createFilter ( config . include || [ /\.vue$/ ] , config . exclude || defaultExclude ) ; } , transform ( code , id ) { if ( ! filter ( id ) ) return ; return transformSFC ( code ) ; } , handleHotUpdate ( ctx ) { const read = ctx . read ; if ( filter ( ctx . file ) ) { ctx . read = async ( ) => { const code = await read ( ) ; return await transformSFC ( code ) || code ; } ; } } , } ; }