vite.config.ts 1.0 KB

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