vite.config.ts 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { resolve } from 'path'
  2. import { sveltekit } from '@sveltejs/kit/vite'
  3. import wasm from 'vite-plugin-wasm'
  4. import topLevelAwait from 'vite-plugin-top-level-await'
  5. import { viteStaticCopy } from 'vite-plugin-static-copy'
  6. import type { UserConfig } from 'vite'
  7. const TARGET = process.env.TARGET
  8. const plugins = [sveltekit()]
  9. if (TARGET === 'web') {
  10. plugins.push(wasm())
  11. plugins.push(topLevelAwait())
  12. plugins.push(
  13. viteStaticCopy({
  14. targets: [
  15. {
  16. src: 'core/wasm/pkg/wasm_bg.wasm',
  17. dest: 'wasm'
  18. }
  19. ]
  20. })
  21. )
  22. }
  23. const config: UserConfig = {
  24. server: {
  25. fs: {
  26. // Allow serving the wasm file from this folder.
  27. allow: ['.']
  28. }
  29. },
  30. plugins,
  31. resolve: {
  32. alias: {
  33. $api:
  34. TARGET === 'tauri'
  35. ? resolve('./src/api/desktop')
  36. : resolve('./src/api/web')
  37. }
  38. }
  39. }
  40. export default config