File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 17
17
"sirv" : " ^2.0.3"
18
18
},
19
19
"devDependencies" : {
20
- "@sveltejs/vite-plugin-svelte" : " ^2.4.1" ,
21
20
"cross-env" : " ^7.0.3" ,
22
21
"svelte" : " workspace:*" ,
23
22
"vite" : " ^4.3.9"
Original file line number Diff line number Diff line change 1
- import { defineConfig } from 'vite' ;
2
- import { svelte } from '@sveltejs/vite-plugin- svelte' ;
1
+ import { createFilter , defineConfig } from 'vite' ;
2
+ import { compile } from '../ svelte/src/compiler ' ;
3
3
4
- // Do not remove this import. It's needed to trigger reloads when the compiler changes.
5
- import { compile } from '../svelte/src/compiler/index.js' ;
4
+ const filter = createFilter ( '**/*.svelte' ) ;
6
5
7
6
// https://vitejs.dev/config/
8
7
export default defineConfig ( {
9
8
plugins : [
10
- svelte ( {
11
- compilerOptions : {
12
- hydratable : true
9
+ {
10
+ name : 'svelte' ,
11
+ transform ( code , id , options ) {
12
+ if ( ! filter ( id ) ) return null ;
13
+
14
+ const compiled = compile ( code , {
15
+ filename : id ,
16
+ generate : options ?. ssr ? 'ssr' : 'dom' ,
17
+ hydratable : true ,
18
+ css : 'injected'
19
+ } ) ;
20
+
21
+ return compiled . js ;
22
+ } ,
23
+ configureServer ( server ) {
24
+ server . watcher . on ( 'change' , ( path ) => {
25
+ if ( path . includes ( 'src/compiler' ) ) {
26
+ // pre-emptively send a full reload so that the request finishes faster
27
+ server . ws . send ( {
28
+ type : 'full-reload'
29
+ } ) ;
30
+ }
31
+ } ) ;
13
32
}
14
- } )
33
+ }
15
34
] ,
16
35
server : {
17
36
watch : {
You can’t perform that action at this time.
0 commit comments