File tree Expand file tree Collapse file tree
packages-integrations/vite/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { LAYER_MARK_ALL } from '#integration/constants'
88import { getHash } from '#integration/hash'
99import { resolveId , resolveLayer } from '#integration/layers'
1010import { getPath } from '#integration/utils'
11- import { toViteVirtualId } from '../../virtual'
11+ import { toViteClientPath , toViteVirtualId } from '../../virtual'
1212import { MESSAGE_UNOCSS_ENTRY_NOT_FOUND } from './shared'
1313
1414const WARN_TIMEOUT = 20000
@@ -75,9 +75,10 @@ export function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[] {
7575 const mod = server . moduleGraph . getModuleById ( id )
7676 if ( ! mod )
7777 return null
78+ const path = toViteClientPath ( mod . url )
7879 return {
79- acceptedPath : mod . url ,
80- path : mod . url ,
80+ acceptedPath : path ,
81+ path,
8182 timestamp : lastServedTime ,
8283 type : 'js-update' ,
8384 } as Update
Original file line number Diff line number Diff line change 11const VITE_VIRTUAL_ID_PREFIX = '\0'
2+ const VITE_CLIENT_ID_PREFIX = '/@id/'
3+ const VITE_NULL_BYTE_PLACEHOLDER = '__x00__'
24
35export function toViteVirtualId ( id : string ) {
46 return id . startsWith ( VITE_VIRTUAL_ID_PREFIX )
57 ? id
68 : `${ VITE_VIRTUAL_ID_PREFIX } ${ id } `
79}
10+
11+ export function toViteClientPath ( id : string ) {
12+ return id . startsWith ( VITE_VIRTUAL_ID_PREFIX )
13+ ? `${ VITE_CLIENT_ID_PREFIX } ${ id . replace ( VITE_VIRTUAL_ID_PREFIX , VITE_NULL_BYTE_PLACEHOLDER ) } `
14+ : id
15+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { resolve } from 'node:path'
22import * as vite from 'vite'
33import { describe , expect , it } from 'vitest'
44import UnoCSS from '../packages-integrations/vite/src/index'
5+ import { toViteClientPath } from '../packages-integrations/vite/src/virtual'
56
67describe ( 'vite virtual module ids' , ( ) => {
78 async function createServer ( mode : 'global' | 'per-module' ) {
@@ -28,6 +29,13 @@ describe('vite virtual module ids', () => {
2829 }
2930 } )
3031
32+ it ( 'converts internal ids to public client paths' , ( ) => {
33+ expect ( toViteClientPath ( '\0/__uno.css' ) )
34+ . toBe ( '/@id/__x00__/__uno.css' )
35+ expect ( toViteClientPath ( '/src/main.ts' ) )
36+ . toBe ( '/src/main.ts' )
37+ } )
38+
3139 it ( 'uses internal ids for per-module CSS' , async ( ) => {
3240 const server = await createServer ( 'per-module' )
3341
You can’t perform that action at this time.
0 commit comments