tsup.config.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig } from "tsup";
  2. import { resolve } from "node:path";
  3. import { pathToFileURL } from "node:url";
  4. // tsup 配置自身会被打包,构建工具需保留原始文件位置,不能被内联后重定位。
  5. const { loadBuiltinProviderConfig } = await import(
  6. pathToFileURL(resolve(import.meta.dirname, "../../scripts/builtin-provider-config.mjs")).href
  7. );
  8. const { content: zcodeBuiltinProviderConfigJson } = await loadBuiltinProviderConfig();
  9. export const SERVER_CLI_DEFINES = {
  10. __ZCODE_BUILTIN_PROVIDER_CONFIG_JSON__: JSON.stringify(zcodeBuiltinProviderConfigJson),
  11. };
  12. export default defineConfig({
  13. entry: {
  14. "server-cli": "src/main.ts",
  15. "server-core": "src/server-core/entry.ts",
  16. },
  17. outDir: "dist",
  18. format: ["esm"],
  19. platform: "node",
  20. target: "node22",
  21. sourcemap: true,
  22. splitting: false,
  23. banner: {
  24. js: 'import { fileURLToPath as __zcodeFileURLToPath } from "node:url"; import { dirname as __zcodeDirname } from "node:path"; const __filename = __zcodeFileURLToPath(import.meta.url); const __dirname = __zcodeDirname(__filename);',
  25. },
  26. noExternal: ["@zcode/shared", "@zcode/rpc", "@zcode/services"],
  27. define: SERVER_CLI_DEFINES,
  28. external: [
  29. "node-pty",
  30. "ssh2",
  31. "yaml",
  32. "node-forge",
  33. "undici",
  34. "axios",
  35. "form-data",
  36. "combined-stream",
  37. "proxy-from-env",
  38. "follow-redirects",
  39. "@lydell/node-pty-darwin-arm64",
  40. "@lydell/node-pty-darwin-x64",
  41. "@lydell/node-pty-linux-arm64",
  42. "@lydell/node-pty-linux-x64",
  43. ],
  44. });