Skip to content

Commit

Permalink
fix: pass Astro config postcss to Svelte preprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Jun 22, 2022
1 parent b9f891b commit d81a0b4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/integrations/svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
})
});
},
},
};
Expand Down

0 comments on commit d81a0b4

Please sign in to comment.