@@ -21,6 +21,8 @@ import {
2121 checkVuePlugin ,
2222 error ,
2323 getVitePlugin ,
24+ getVitePluginTransform ,
25+ overrideVitePluginTransform ,
2426 raiseError ,
2527 resolveNamespace ,
2628 warn
@@ -136,11 +138,24 @@ export function resourcePlugin(
136138 `configResolved: isProduction = ${ isProduction } , sourceMap = ${ sourceMap } `
137139 )
138140
141+ /**
142+ * NOTE:
143+ * For the native rolldown plugin, we need to change to another solution from the current workaround.
144+ * Currently, the rolldown team and vite team are discussing this issue.
145+ * https://github.com/vitejs/rolldown-vite/issues/120
146+ */
147+
139148 // json transform handling
140149 const jsonPlugin = getVitePlugin ( config , 'vite:json' )
141150 if ( jsonPlugin ) {
142- const orgTransform = jsonPlugin . transform // backup @rollup /plugin-json
143- jsonPlugin . transform = async function ( code : string , id : string ) {
151+ // saving `vite:json` plugin instance
152+ const [ orgTransform , transformWay ] =
153+ getVitePluginTransform ( jsonPlugin )
154+ if ( ! orgTransform ) {
155+ throw new Error ( 'vite:json plugin not found!' )
156+ }
157+
158+ async function overrideViteJsonPlugin ( code : string , id : string ) {
144159 if ( ! / \. j s o n $ / . test ( id ) || filter ( id ) ) {
145160 return
146161 }
@@ -162,6 +177,13 @@ export function resourcePlugin(
162177 // @ts -expect-error
163178 return orgTransform ! . apply ( this , [ code , id ] )
164179 }
180+
181+ // override `vite:json` plugin transform function
182+ overrideVitePluginTransform (
183+ jsonPlugin ,
184+ overrideViteJsonPlugin ,
185+ transformWay !
186+ )
165187 }
166188
167189 /**
0 commit comments