1
1
import type { Options } from '@sveltejs/vite-plugin-svelte' ;
2
+ import type { AstroIntegration , AstroRenderer , AstroConfig } from 'astro' ;
3
+ import type { UserConfig } from 'vite'
2
4
import { svelte } from '@sveltejs/vite-plugin-svelte' ;
3
- import type { AstroIntegration , AstroRenderer } from 'astro' ;
4
5
import preprocess from 'svelte-preprocess' ;
5
6
6
7
function getRenderer ( ) : AstroRenderer {
@@ -11,13 +12,20 @@ function getRenderer(): AstroRenderer {
11
12
} ;
12
13
}
13
14
14
- function getViteConfiguration ( isDev : boolean , options ?: Options | OptionsCallback ) {
15
- const defaultOptions = {
15
+ type ViteConfigurationArgs = {
16
+ isDev : boolean ;
17
+ options ?: Options | OptionsCallback ;
18
+ postcssConfig : AstroConfig [ 'style' ] [ 'postcss' ] ;
19
+ }
20
+
21
+ function getViteConfiguration ( { options, postcssConfig, isDev } : ViteConfigurationArgs ) : UserConfig {
22
+ const defaultOptions : Partial < Options > = {
16
23
emitCss : true ,
17
24
compilerOptions : { dev : isDev , hydratable : true } ,
18
25
preprocess : [
19
26
preprocess ( {
20
27
less : true ,
28
+ postcss : postcssConfig ,
21
29
sass : { renderSync : true } ,
22
30
scss : { renderSync : true } ,
23
31
stylus : true ,
@@ -61,9 +69,15 @@ export default function (options?: Options | OptionsCallback): AstroIntegration
61
69
name : '@astrojs/svelte' ,
62
70
hooks : {
63
71
// Anything that gets returned here is merged into Astro Config
64
- 'astro:config:setup' : ( { command, updateConfig, addRenderer } ) => {
72
+ 'astro:config:setup' : ( { command, updateConfig, addRenderer, config } ) => {
65
73
addRenderer ( getRenderer ( ) ) ;
66
- updateConfig ( { vite : getViteConfiguration ( command === 'dev' , options ) } ) ;
74
+ updateConfig ( {
75
+ vite : getViteConfiguration ( {
76
+ options,
77
+ isDev : command === 'dev' ,
78
+ postcssConfig : config . style . postcss ,
79
+ } )
80
+ } ) ;
67
81
} ,
68
82
} ,
69
83
} ;
0 commit comments