@@ -24,10 +24,12 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
2424 const cwd = process . cwd ( ) ;
2525 const pluginName = 'unplugin-mlut' ;
2626 const finalOptions : Options = { output : '' } ;
27- const inputPath = options . input && path . resolve ( cwd , options . input ) ;
27+ let inputPath = options . input && path . resolve ( cwd , options . input ) ;
2828 let outputPath = '' ;
29+ let viteWatchOutputPath = '' ;
2930 let lastCompiledCss = '' ;
3031 const isWebpack = meta . framework === 'webpack' ;
32+ const isWindows = process . platform === 'win32' ;
3133 let isVite = false ;
3234 let isViteWatch = false ;
3335
@@ -84,6 +86,13 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
8486 outputPath = path . resolve ( cwd , finalOptions . output ) ;
8587
8688 if ( isViteWatch ) {
89+ if ( isWindows ) {
90+ viteWatchOutputPath = path . isAbsolute ( finalOptions . output ) ?
91+ finalOptions . output . replace ( cwd , '' ) : finalOptions . output ;
92+ } else {
93+ viteWatchOutputPath = outputPath ;
94+ }
95+
8796 await fs . outputFile ( outputPath , '' ) . catch ( ( ) => undefined ) ;
8897 }
8998 } ;
@@ -95,6 +104,7 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
95104 // TODO: add the Vite types
96105 async config ( _config : unknown , { command } : { command : string } ) {
97106 isVite = true ;
107+ inputPath = inputPath ?. replaceAll ( '\\' , '/' ) ;
98108
99109 if ( command === 'serve' ) {
100110 isViteWatch = true ;
@@ -149,6 +159,11 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
149159
150160 transform ( code , id ) {
151161 jitEngine . putContent ( id , code ) ;
162+
163+ if ( isViteWatch ) {
164+ debouncedWriteCssFile ( ) ;
165+ }
166+
152167 return null ;
153168 } ,
154169
@@ -164,7 +179,7 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
164179 tags : [
165180 {
166181 tag : 'link' ,
167- attrs : { rel : 'stylesheet' , href : outputPath } ,
182+ attrs : { rel : 'stylesheet' , href : viteWatchOutputPath } ,
168183 } ,
169184 ] ,
170185 } ;
0 commit comments