Use Svelte components within Astro with server-side rendering and client-side hydration
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core integration configuration for enabling Svelte components in Astro with Vite plugin setup and build optimization.
Creates and configures the main Svelte integration for Astro projects.
/**
* Creates the main Svelte integration for Astro
* @param options - Optional Svelte plugin configuration from @sveltejs/vite-plugin-svelte
* @returns Configured AstroIntegration instance
*/
function svelteIntegration(options?: Options): AstroIntegration;
interface AstroIntegration {
name: string;
hooks: {
'astro:config:setup': (params: ConfigSetupParams) => Promise<void>;
};
}
interface ConfigSetupParams {
updateConfig: (config: AstroUserConfig) => void;
addRenderer: (renderer: AstroRenderer) => void;
}
interface AstroRenderer {
name: string;
clientEntrypoint: string;
serverEntrypoint: string;
}Usage Examples:
// Basic usage
import svelte from '@astrojs/svelte';
export default defineConfig({
integrations: [svelte()]
});
// With options
import svelte from '@astrojs/svelte';
import { vitePreprocess } from '@astrojs/svelte';
export default defineConfig({
integrations: [
svelte({
preprocess: [vitePreprocess()],
compilerOptions: {
dev: process.env.NODE_ENV === 'development',
hydratable: true
},
emitCss: true,
hot: true
})
]
});Provides a container renderer for server-side rendering in isolated contexts.
/**
* Creates a container renderer for isolated SSR contexts
* @returns ContainerRenderer configuration
*/
function getContainerRenderer(): ContainerRenderer;
interface ContainerRenderer {
name: string;
serverEntrypoint: string;
}Internal function that creates the renderer configuration for Astro.
function getRenderer(): AstroRenderer;This function is used internally by the integration and sets up:
@astrojs/svelte/client.js@astrojs/svelte/server.js@astrojs/svelteThe integration automatically configures Vite with:
The integration accepts all options from @sveltejs/vite-plugin-svelte:
type Options = import('@sveltejs/vite-plugin-svelte').Options;
// Key configuration options from @sveltejs/vite-plugin-svelte
interface ViteSvelteOptions {
preprocess?: Preprocessor | Preprocessor[];
compilerOptions?: CompileOptions;
emitCss?: boolean;
hot?: boolean;
inspector?: boolean;
disableDependencyReinclusion?: string[];
vitePlugin?: {
exclude?: string[];
include?: string[];
};
}
type Preprocessor = import('@sveltejs/vite-plugin-svelte').Preprocessor;
type CompileOptions = import('svelte/compiler').CompileOptions;
type AstroUserConfig = import('astro').AstroUserConfig;