Ant Design Svelte

Svelte and Vite

Use Vite for a Svelte application without server routes. The library needs the Svelte plugin; React plugins and Ant Design import tools are not used here.

Preparing application

For a new application, choose the Svelte template with TypeScript:

npm create vite@latest my-app -- --template svelte-ts
cd my-app
npm install @woodger/antd

For an existing project, run the install command from its root directory. Choose a Node.js version supported by your version of Vite.

Svelte plugin

The template already contains a plugin. Minimum vite.config.ts:

import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
  plugins: [svelte()]
});

Do not replace the entire existing config if it contains other plugins, aliases, or publishing options. SvelteKit uses another plugin - sveltekit().

Entry point and first component

Copy the complete source first example to src/App.svelte. It already contains the ConfigProvider, so the library styles will be included along with it.

In src/main.ts the application is mounted via Svelte 5:

import { mount } from 'svelte';
import App from './App.svelte';

const target = document.getElementById('app');

if (!target) {
  throw new Error('Missing #app');
}

mount(App, { target });

In index.html the <div id="app"></div> and connection /src/main.ts created by the template should remain. If ConfigProvider is not used, import @woodger/antd/styles.css into main.ts once.

Development and assembly

npm run dev
npm run build
npm run preview

Preview checks the build result locally. It does not replace a production web server. The publication path is configured via Vite base to the address of the application itself, and not the address of the library documentation. For server rendering use SvelteKit and SSR manual.