esbuild.config.mjs 3.8 KB

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