@@ -26,6 +26,8 @@ export function preprocess(api) {
26
26
*/
27
27
let preprocessSvelte ;
28
28
29
+ const transformHookCacheKey = Symbol ( 'transform-hook' ) ;
30
+
29
31
/** @type {import('vite').Plugin } */
30
32
const plugin = {
31
33
name : 'vite-plugin-svelte:preprocess' ,
@@ -34,18 +36,26 @@ export function preprocess(api) {
34
36
options = api . options ;
35
37
if ( arraify ( options . preprocess ) . length > 0 ) {
36
38
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
+ }
37
43
// @ts -expect-error defined below but filter not in type
38
44
plugin . transform . filter = api . filter ;
39
45
} 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
+ }
45
57
// @ts -expect-error force set undefined to clear memory
46
58
preprocessSvelte = undefined ;
47
- // @ts -expect-error defined below but filter not in type
48
- plugin . transform . filter = { id : / $ ./ } ; // never match
49
59
}
50
60
} ,
51
61
configureServer ( server ) {
0 commit comments