@@ -5,21 +5,24 @@ import process from 'node:process'
55import { notNull } from '@unocss/core'
66import MagicString from 'magic-string'
77import { getHash , getPath , LAYER_MARK_ALL , resolveId , resolveLayer } from '../../integration'
8+ import { MESSAGE_UNOCSS_ENTRY_NOT_FOUND } from './shared'
89
910const WARN_TIMEOUT = 20000
1011const WS_EVENT_PREFIX = 'unocss:hmr'
1112const HASH_LENGTH = 6
1213
14+ type TimeoutTimer = ReturnType < typeof setTimeout > | undefined
15+
1316export function GlobalModeDevPlugin ( ctx : UnocssPluginContext ) : Plugin [ ] {
1417 const { tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig } = ctx
1518 const servers : ViteDevServer [ ] = [ ]
1619 const entries = new Set < string > ( )
1720
18- let invalidateTimer : any
21+ let invalidateTimer : TimeoutTimer
1922 const lastServedHash = new Map < string , string > ( )
2023 let lastServedTime = Date . now ( )
2124 let resolved = false
22- let resolvedWarnTimer : any
25+ let resolvedWarnTimer : TimeoutTimer
2326
2427 async function generateCSS ( layer : string ) {
2528 await flushTasks ( )
@@ -80,17 +83,20 @@ export function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[] {
8083 }
8184 }
8285
83- function setWarnTimer ( ) {
84- if ( ! resolved && ! resolvedWarnTimer ) {
86+ async function setWarnTimer ( ) {
87+ if (
88+ ! resolved
89+ && ! resolvedWarnTimer
90+ && ( await getConfig ( ) as VitePluginConfig ) . checkImport
91+ ) {
8592 resolvedWarnTimer = setTimeout ( ( ) => {
8693 if ( process . env . TEST || process . env . NODE_ENV === 'test' )
8794 return
8895 if ( ! resolved ) {
89- const msg = '[unocss] Entry module not found. Did you add `import \'uno.css\'` in your main entry?'
90- console . warn ( msg )
96+ console . warn ( MESSAGE_UNOCSS_ENTRY_NOT_FOUND )
9197 servers . forEach ( ( { ws } ) => ws . send ( {
9298 type : 'error' ,
93- err : { message : msg , stack : '' } ,
99+ err : { message : MESSAGE_UNOCSS_ENTRY_NOT_FOUND , stack : '' } ,
94100 } ) )
95101 }
96102 } , WARN_TIMEOUT )
0 commit comments