@@ -93,9 +93,11 @@ const createViteServer = async ({
9393 root,
9494 identifiers,
9595 viteConfig,
96+ enableFileWatcher = true ,
9697} : Required <
9798 Pick < CreateCompilerOptions , 'root' | 'identifiers' | 'viteConfig' >
98- > ) => {
99+ > &
100+ Pick < CreateCompilerOptions , 'enableFileWatcher' > ) => {
99101 const pkg = getPackageInfo ( root ) ;
100102 const vite = await import ( 'vite' ) ;
101103
@@ -108,6 +110,7 @@ const createViteServer = async ({
108110 root,
109111 server : {
110112 hmr : false ,
113+ watch : enableFileWatcher ? undefined : null ,
111114 } ,
112115 logLevel : 'silent' ,
113116 optimizeDeps : {
@@ -194,9 +197,11 @@ const createViteServer = async ({
194197 } ,
195198 } ) ;
196199
197- server . watcher . on ( 'change' , ( filePath ) => {
198- runner . moduleCache . invalidateDepTree ( [ filePath ] ) ;
199- } ) ;
200+ if ( enableFileWatcher ) {
201+ server . watcher . on ( 'change' , ( filePath ) => {
202+ runner . moduleCache . invalidateDepTree ( [ filePath ] ) ;
203+ } ) ;
204+ }
200205
201206 return {
202207 server,
@@ -244,6 +249,13 @@ interface ProcessedVanillaFile {
244249
245250export interface CreateCompilerOptions {
246251 root : string ;
252+ /**
253+ * By default, the compiler sets up its own file watcher. This option allows you to disable it if
254+ * necessary, such as during a production build.
255+ *
256+ * @default true
257+ */
258+ enableFileWatcher ?: boolean ;
247259 cssImportSpecifier ?: ( filePath : string ) => string ;
248260 identifiers ?: IdentifierOption ;
249261 viteConfig ?: ViteUserConfig ;
@@ -257,6 +269,7 @@ export const createCompiler = ({
257269 identifiers = 'debug' ,
258270 cssImportSpecifier = ( filePath ) => filePath + '.vanilla.css' ,
259271 viteConfig,
272+ enableFileWatcher,
260273 viteResolve,
261274 vitePlugins,
262275} : CreateCompilerOptions ) : Compiler => {
@@ -272,6 +285,7 @@ export const createCompiler = ({
272285 resolve : viteResolve ,
273286 plugins : vitePlugins ,
274287 } ,
288+ enableFileWatcher,
275289 } ) ;
276290
277291 const processVanillaFileCache = new Map <
@@ -388,8 +402,8 @@ export const createCompiler = ({
388402 throw new Error ( `Can't find ModuleNode for ${ filePath } ` ) ;
389403 }
390404
391- const cssImports = [ ] ;
392- const orderedComposedClassLists = [ ] ;
405+ const cssImports : string [ ] = [ ] ;
406+ const orderedComposedClassLists : Composition [ ] = [ ] ;
393407
394408 const scanModule = createModuleScanner ( ) ;
395409 const { cssDeps, watchFiles } = scanModule ( moduleNode ) ;
0 commit comments