summaryrefslogtreecommitdiff
path: root/packages/integrations/svelte/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/svelte/src/index.ts')
-rw-r--r--packages/integrations/svelte/src/index.ts24
1 files changed, 19 insertions, 5 deletions
diff --git a/packages/integrations/svelte/src/index.ts b/packages/integrations/svelte/src/index.ts
index 340e2def0..268d5a590 100644
--- a/packages/integrations/svelte/src/index.ts
+++ b/packages/integrations/svelte/src/index.ts
@@ -1,6 +1,7 @@
import type { Options } from '@sveltejs/vite-plugin-svelte';
+import type { AstroIntegration, AstroRenderer, AstroConfig } from 'astro';
+import type { UserConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte';
-import type { AstroIntegration, AstroRenderer } from 'astro';
import preprocess from 'svelte-preprocess';
function getRenderer(): AstroRenderer {
@@ -11,13 +12,20 @@ function getRenderer(): AstroRenderer {
};
}
-function getViteConfiguration(isDev: boolean, options?: Options | OptionsCallback) {
- const defaultOptions = {
+type ViteConfigurationArgs = {
+ isDev: boolean;
+ options?: Options | OptionsCallback;
+ postcssConfig: AstroConfig['style']['postcss'];
+}
+
+function getViteConfiguration({ options, postcssConfig, isDev }: ViteConfigurationArgs): UserConfig {
+ const defaultOptions: Partial<Options> = {
emitCss: true,
compilerOptions: { dev: isDev, hydratable: true },
preprocess: [
preprocess({
less: true,
+ postcss: postcssConfig,
sass: { renderSync: true },
scss: { renderSync: true },
stylus: true,
@@ -61,9 +69,15 @@ export default function (options?: Options | OptionsCallback): AstroIntegration
name: '@astrojs/svelte',
hooks: {
// Anything that gets returned here is merged into Astro Config
- 'astro:config:setup': ({ command, updateConfig, addRenderer }) => {
+ 'astro:config:setup': ({ command, updateConfig, addRenderer, config }) => {
addRenderer(getRenderer());
- updateConfig({ vite: getViteConfiguration(command === 'dev', options) });
+ updateConfig({
+ vite: getViteConfiguration({
+ options,
+ isDev: command === 'dev',
+ postcssConfig: config.style.postcss,
+ })
+ });
},
},
};