Skip to content

How to use svelte.config.js with Vitest similar to vite.config.js #331

Answered by dominikg
EstebanBorai asked this question in Q&A
Discussion options

You must be logged in to vote

for component testing you can use a separate vite+svelte setup and share aliases like this

svelte.config.js

export const sveltekitViteConfig = {
  resolve: {
    alias: {
      $i18n: path.resolve('./src/i18n'),
      $lib: path.resolve('./src/lib'),
    },
  },
}

/** @type {import('@sveltejs/kit').Config} */
const config = {
  kit: {
    adapter: adapter(),

    // hydrate the <div id="svelte"> element in src/app.html
    target: '#svelte',
    vite: sveltekitViteConfig,
  },
}

export default config

vitest.config.ts

import type { UserConfig } from 'vite'
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { sveltekitViteConfig } from './svel…

Replies: 4 comments 11 replies

Comment options

You must be logged in to vote
2 replies
@EstebanBorai
Comment options

@benmccann
Comment options

Comment options

You must be logged in to vote
7 replies
@benmccann
Comment options

@EstebanBorai
Comment options

@cibernox
Comment options

@EstebanBorai
Comment options

@benmccann
Comment options

Answer selected by EstebanBorai
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@nickbreaton
Comment options

@benmccann
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants