2
0

esbuild.config.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* eslint-disable no-undef */
  2. import esbuild from "esbuild"
  3. import { chmodSync, mkdirSync, copyFileSync } from "fs"
  4. import { rimrafSync } from "rimraf"
  5. // Function to copy post-build files
  6. function copyPostBuildFiles() {
  7. try {
  8. mkdirSync("dist/config", { recursive: true })
  9. copyFileSync("src/config/schema.json", "dist/config/schema.json")
  10. copyFileSync("package.dist.json", "dist/package.json")
  11. copyFileSync("README.md", "dist/README.md")
  12. try {
  13. copyFileSync(".env", "dist/.env")
  14. copyFileSync(".env", "dist/kilocode/.env")
  15. } catch {
  16. // .env might not exist, that's okay
  17. }
  18. console.log("✓ Post-build files copied")
  19. } catch (err) {
  20. console.error("Error copying post-build files:", err)
  21. }
  22. }
  23. function removeUnneededFiles() {
  24. rimrafSync("dist/kilocode/webview-ui")
  25. rimrafSync("dist/kilocode/assets")
  26. console.log("✓ Unneeded files removed")
  27. }
  28. const afterBuildPlugin = {
  29. name: "after-build",
  30. setup(build) {
  31. build.onEnd((result) => {
  32. if (result.errors.length > 0) return
  33. copyPostBuildFiles()
  34. removeUnneededFiles()
  35. try {
  36. chmodSync("dist/index.js", 0o755)
  37. console.log("✓ dist/index.js made executable")
  38. } catch (err) {
  39. console.error("Error making dist/index.js executable:", err)
  40. }
  41. })
  42. },
  43. }
  44. const config = {
  45. entryPoints: ["src/index.ts"],
  46. bundle: true,
  47. platform: "node",
  48. target: "node20",
  49. format: "esm",
  50. outfile: "dist/index.js",
  51. banner: {
  52. js: `import { createRequire as __createRequire__ } from 'module';
  53. import { fileURLToPath as __fileURLToPath__ } from 'url';
  54. import { dirname as __dirname__ } from 'path';
  55. const require = __createRequire__(import.meta.url);
  56. const __filename = __fileURLToPath__(import.meta.url);
  57. const __dirname = __dirname__(__filename);
  58. `,
  59. },
  60. external: [
  61. // Keep these as external dependencies (will be installed via npm)
  62. "@anthropic-ai/bedrock-sdk",
  63. "@anthropic-ai/sdk",
  64. "@anthropic-ai/vertex-sdk",
  65. "@aws-sdk/client-bedrock-runtime",
  66. "@aws-sdk/credential-providers",
  67. "@google/genai",
  68. "@lmstudio/sdk",
  69. "@mistralai/mistralai",
  70. "@modelcontextprotocol/sdk",
  71. "@qdrant/js-client-rest",
  72. "@vscode/codicons",
  73. "@vscode/ripgrep",
  74. "async-mutex",
  75. "axios",
  76. "chalk",
  77. "cheerio",
  78. "chokidar",
  79. "clone-deep",
  80. "commander",
  81. "default-shell",
  82. "delay",
  83. "diff",
  84. "diff-match-patch",
  85. "dotenv",
  86. "eventemitter3",
  87. "exceljs",
  88. "fast-deep-equal",
  89. "fast-xml-parser",
  90. "fastest-levenshtein",
  91. "fs-extra",
  92. "fuse.js",
  93. "fzf",
  94. "get-folder-size",
  95. "google-auth-library",
  96. "gray-matter",
  97. "i18next",
  98. "ignore",
  99. "ink",
  100. "ink-big-text",
  101. "ink-gradient",
  102. "ink-select-input",
  103. "ink-spinner",
  104. "ink-table",
  105. "ink-text-input",
  106. "is-wsl",
  107. "isbinaryfile",
  108. "jotai",
  109. "jsdom",
  110. "json5",
  111. "jwt-decode",
  112. "lodash.debounce",
  113. "lru-cache",
  114. "mammoth",
  115. "marked",
  116. "marked-terminal",
  117. "monaco-vscode-textmate-theme-converter",
  118. "node-cache",
  119. "node-ipc",
  120. "ollama",
  121. "openai",
  122. "os-name",
  123. "p-limit",
  124. "p-wait-for",
  125. "pdf-parse",
  126. "pkce-challenge",
  127. "pretty-bytes",
  128. "proper-lockfile",
  129. "ps-tree",
  130. "puppeteer-chromium-resolver",
  131. "puppeteer-core",
  132. "react",
  133. "reconnecting-eventsource",
  134. "sanitize-filename",
  135. "say",
  136. "serialize-error",
  137. "shiki",
  138. "simple-git",
  139. "socket.io-client",
  140. "sound-play",
  141. "stream-json",
  142. "strip-ansi",
  143. "strip-bom",
  144. "tiktoken",
  145. "tmp",
  146. "tree-sitter-wasms",
  147. "ts-node",
  148. "turndown",
  149. "undici",
  150. "uri-js",
  151. "uuid",
  152. "vscode-material-icons",
  153. "vscode-uri",
  154. "web-tree-sitter",
  155. "workerpool",
  156. "yaml",
  157. "zod",
  158. ],
  159. sourcemap: false,
  160. minify: false,
  161. treeShaking: true,
  162. logLevel: "info",
  163. plugins: [afterBuildPlugin],
  164. }
  165. if (process.argv.includes("--watch")) {
  166. const ctx = await esbuild.context(config)
  167. await ctx.watch()
  168. console.log("Watching for changes...")
  169. } else {
  170. // Single build
  171. await esbuild.build(config)
  172. }