vite.config.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. build: {
  21. sourcemap: true,
  22. },
  23. resolve: {
  24. // Workspace packages resolve to SOURCE: package.json exports point at lib
  25. // for Node/type consumers, but the browser bundle must compile src directly
  26. // so CSS rides vite's pipeline instead of the CSS-externalized lib bundle.
  27. // Only the shell's normal-package surface is aliased — plugin packages are
  28. // NEVER bundled here (web2 shell self-sufficiency); they arrive as runtime
  29. // bundles through the client module system. Order matters — subpath
  30. // aliases must win over bare-name prefixes.
  31. alias: [
  32. // Browserization of the vendored cordis Loader: its only node-only
  33. // import; the two process probes are mapped by `define` below.
  34. { find: /^node:module$/, replacement: src('./src/node-module-stub.ts') },
  35. { find: /^@deepseek-ai\/dsh-client-web$/, replacement: src('../../packages/client/web/src/boot.tsx') },
  36. { find: /^@deepseek-ai\/dsh-client-web-react$/, replacement: src('../../packages/client/web-react/src/index.ts') },
  37. { find: /^@deepseek-ai\/dsh-client-ui-slots$/, replacement: src('../../packages/client/ui-slots/src/index.ts') },
  38. { find: /^@deepseek-ai\/dsh-client-ui-primitives$/, replacement: src('../../packages/client/ui-primitives/src/index.ts') },
  39. { find: /^@deepseek-ai\/dsh-client-schema-form$/, replacement: src('../../packages/client/schema-form/src/index.ts') },
  40. { find: /^@deepseek-ai\/dsh-client-modules\/client$/, replacement: src('../../packages/client/modules/src/client/index.ts') },
  41. ],
  42. },
  43. define: {
  44. // vendored loader internal.ts: fromInternal() probes the Node major —
  45. // "0.0.0" takes neither branch, returning undefined (exactly the empty
  46. // internal slot the shell boot fills with the client module loader).
  47. 'process.versions.node': '"0.0.0"',
  48. 'process.execArgv': '[]',
  49. // vendored loader index.ts: envData falls to its default branch.
  50. 'process.env.CORDIS_SHARED': 'undefined',
  51. },
  52. })