@@ -26,6 +26,8 @@ export function preprocess(api) {
2626 */
2727 let preprocessSvelte ;
2828
29+ const transformHookCacheKey = Symbol ( 'transform-hook' ) ;
30+
2931 /** @type {import('vite').Plugin } */
3032 const plugin = {
3133 name : 'vite-plugin-svelte:preprocess' ,
@@ -34,18 +36,26 @@ export function preprocess(api) {
3436 options = api . options ;
3537 if ( arraify ( options . preprocess ) . length > 0 ) {
3638 preprocessSvelte = createPreprocessSvelte ( options , c ) ;
39+ if ( ! plugin . transform && Object . hasOwn ( plugin , transformHookCacheKey ) ) {
40+ // @ts -expect-error custom cache prop
41+ plugin . transform = plugin [ transformHookCacheKey ] ;
42+ }
3743 // @ts -expect-error defined below but filter not in type
3844 plugin . transform . filter = api . filter ;
3945 } else {
40- log . debug (
41- `disabling ${ plugin . name } because no preprocessor is configured` ,
42- undefined ,
43- 'preprocess'
44- ) ;
46+ if ( plugin . transform ) {
47+ log . debug (
48+ `disabling ${ plugin . name } because no preprocessor is configured` ,
49+ undefined ,
50+ 'preprocess'
51+ ) ;
52+ if ( ! Object . hasOwn ( plugin , transformHookCacheKey ) ) {
53+ Object . defineProperty ( plugin , transformHookCacheKey , { value : plugin . transform } ) ;
54+ }
55+ delete plugin . transform ;
56+ }
4557 // @ts -expect-error force set undefined to clear memory
4658 preprocessSvelte = undefined ;
47- // @ts -expect-error defined below but filter not in type
48- plugin . transform . filter = { id : / $ ./ } ; // never match
4959 }
5060 } ,
5161 configureServer ( server ) {
0 commit comments