@@ -73,14 +73,14 @@ function injectProviderComponent(
7373 id : string ,
7474 config ?: boolean ,
7575 defaultConfig ?: boolean ,
76- ) : string {
76+ ) : { code : string ; map ?: any } {
7777 let root : RootNode
7878 try {
7979 root = parse ( code )
8080 } catch ( err ) {
8181 console . warn ( 'Failed to parse SFC:' , code )
8282 console . error ( err )
83- return code
83+ return { code }
8484 }
8585 const open = `<FormKitLazyProvider${ config ? ' config-file="true"' : '' } ${
8686 defaultConfig ? '' : ' :default-config="false"'
@@ -91,7 +91,7 @@ function injectProviderComponent(
9191 console . warn (
9292 `To <template> block found in ${ id } . Skipping FormKitLazyProvider injection.` ,
9393 )
94- return code
94+ return { code, map : null }
9595 }
9696 const before = code . substring ( 0 , template . loc . start . offset + 10 )
9797 const content = code . substring (
@@ -100,7 +100,8 @@ function injectProviderComponent(
100100 )
101101 const after = code . substring ( template . loc . end . offset - 11 )
102102 code = `${ before } \n${ open } ${ content } ${ close } \n${ after } `
103- return code
103+
104+ return { code, map : null }
104105}
105106
106107/**
@@ -145,6 +146,15 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
145146 return {
146147 name : 'unplugin-formkit' ,
147148 enforce : 'pre' ,
149+ vite : {
150+ config ( ) {
151+ return {
152+ optimizeDeps : {
153+ exclude : [ '@formkit/vue' ] ,
154+ } ,
155+ }
156+ } ,
157+ } ,
148158 // webpack's id filter is outside of loader logic,
149159 // an additional hook is needed for better perf on webpack
150160 transformInclude ( id : string ) {
@@ -174,17 +184,19 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
174184 '' ,
175185 )
176186 }
187+ // Parse the modified code using recast and return the code with a sourcemap.
188+ return { code, map : null }
177189 }
178190 // Test if the given code is a likely candidate for FormKit usage.
179191 if ( id . endsWith ( '.vue' ) && CONTAINS_FORMKIT_RE . test ( code ) ) {
180- code = injectProviderComponent (
192+ return injectProviderComponent (
181193 injectProviderImport ( code ) ,
182194 id ,
183195 ! ! configPath ,
184196 options . defaultConfig ,
185197 )
186198 }
187- return code
199+ return
188200 } ,
189201 }
190202}
0 commit comments