vite.config.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { fileURLToPath } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import type { Plugin } from 'vite'
  4. import react from '@vitejs/plugin-react'
  5. const src = (rel: string): string => fileURLToPath(new URL(rel, import.meta.url))
  6. const STANDALONE_ERROR = 'apps/web is not a standalone application: bare Vite cannot inject window.__DSH_BOOT__. '
  7. + 'Build with `pnpm run build && pnpm run build:web`, then run `dsh web` (repository checkout: `pnpm run dsh -- web`). '
  8. + 'For client-plugin HMR, run `pnpm run dsh -- web --dev` together with `pnpm run dev:web`.'
  9. /** Fail before a Vite dev or preview server can expose the boot-manifest-free shell. */
  10. function rejectStandaloneServe(): Plugin {
  11. return {
  12. name: 'dsh-reject-standalone-web-serve',
  13. config(_config, env) {
  14. if (env.command === 'serve') throw new Error(STANDALONE_ERROR)
  15. },
  16. }
  17. }
  18. export default defineConfig({
  19. plugins: [rejectStandaloneServe(), react()],
  20. resolve: {
  21. // Workspace packages resolve to SOURCE: package.json exports point at lib
  22. // for Node/type consumers, but the browser bundle must compile src directly
  23. // so CSS rides vite's pipeline instead of the CSS-externalized lib bundle.
  24. // Only the shell's normal-package surface is aliased — plugin packages are
  25. // NEVER bundled here (web2 shell self-sufficiency); they arrive as runtime
  26. // bundles through the client module system. Order matters — subpath
  27. // aliases must win over bare-name prefixes.
  28. alias: [
  29. // Browserization of the vendored cordis Loader: its only node-only
  30. // import; the two process probes are mapped by `define` below.
  31. { find: /^node:module$/, replacement: src('./src/node-module-stub.ts') },
  32. { find: /^@deepseek-ai\/dsh-client-web$/, replacement: src('../../packages/client/web/src/boot.tsx') },
  33. { find: /^@deepseek-ai\/dsh-client-web-react$/, replacement: src('../../packages/client/web-react/src/index.ts') },
  34. { find: /^@deepseek-ai\/dsh-client-ui-slots$/, replacement: src('../../packages/client/ui-slots/src/index.ts') },
  35. { find: /^@deepseek-ai\/dsh-client-ui-primitives$/, replacement: src('../../packages/client/ui-primitives/src/index.ts') },
  36. { find: /^@deepseek-ai\/dsh-client-schema-form$/, replacement: src('../../packages/client/schema-form/src/index.ts') },
  37. { find: /^@deepseek-ai\/dsh-client-modules\/client$/, replacement: src('../../packages/client/modules/src/client/index.ts') },
  38. ],
  39. },
  40. define: {
  41. // vendored loader internal.ts: fromInternal() probes the Node major —
  42. // "0.0.0" takes neither branch, returning undefined (exactly the empty
  43. // internal slot the shell boot fills with the client module loader).
  44. 'process.versions.node': '"0.0.0"',
  45. 'process.execArgv': '[]',
  46. // vendored loader index.ts: envData falls to its default branch.
  47. 'process.env.CORDIS_SHARED': 'undefined',
  48. },
  49. })