@@ -5,21 +5,24 @@ import process from 'node:process'
5
5
import { notNull } from '@unocss/core'
6
6
import MagicString from 'magic-string'
7
7
import { getHash , getPath , LAYER_MARK_ALL , resolveId , resolveLayer } from '../../integration'
8
+ import { MESSAGE_UNOCSS_ENTRY_NOT_FOUND } from './shared'
8
9
9
10
const WARN_TIMEOUT = 20000
10
11
const WS_EVENT_PREFIX = 'unocss:hmr'
11
12
const HASH_LENGTH = 6
12
13
14
+ type TimeoutTimer = ReturnType < typeof setTimeout > | undefined
15
+
13
16
export function GlobalModeDevPlugin ( ctx : UnocssPluginContext ) : Plugin [ ] {
14
17
const { tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig } = ctx
15
18
const servers : ViteDevServer[ ] = [ ]
16
19
const entries = new Set < string > ( )
17
20
18
- let invalidateTimer : any
21
+ let invalidateTimer : TimeoutTimer
19
22
const lastServedHash = new Map < string , string > ( )
20
23
let lastServedTime = Date . now ( )
21
24
let resolved = false
22
- let resolvedWarnTimer : any
25
+ let resolvedWarnTimer : TimeoutTimer
23
26
24
27
async function generateCSS ( layer : string ) {
25
28
await flushTasks ( )
@@ -80,17 +83,20 @@ export function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[] {
80
83
}
81
84
}
82
85
83
- function setWarnTimer ( ) {
84
- if ( ! resolved && ! resolvedWarnTimer ) {
86
+ async function setWarnTimer ( ) {
87
+ if (
88
+ ! resolved
89
+ && ! resolvedWarnTimer
90
+ && ( await getConfig ( ) as VitePluginConfig ) . checkImport
91
+ ) {
85
92
resolvedWarnTimer = setTimeout ( ( ) => {
86
93
if ( process . env . TEST || process . env . NODE_ENV === 'test' )
87
94
return
88
95
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 )
91
97
servers . forEach ( ( { ws } ) => ws . send ( {
92
98
type : 'error' ,
93
- err : { message : msg , stack : '' } ,
99
+ err : { message : MESSAGE_UNOCSS_ENTRY_NOT_FOUND , stack : '' } ,
94
100
} ) )
95
101
}
96
102
} , WARN_TIMEOUT )
0 commit comments