paperclip/ui/vite.config.ts

36 lines
906 B
TypeScript
Raw Normal View History

import path from "path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
chore(ui): drop console.* and legal comments in production builds (#3728) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The web UI is a single-page app built with Vite and shipped as a static bundle to every deployment > - Production bundles carry `console.log` / `console.debug` calls from dev code and `/*! … */` legal-comment banners from third-party packages > - The console calls leak internals to anyone opening devtools and waste bytes per call site; the legal banners accumulate throughout the bundle > - Both problems affect every self-hoster, since they all ship the same UI bundle > - This pull request configures esbuild (via `vite.config.ts`) to strip `console` and `debugger` statements and drop inline legal comments from production builds only ## What Changed - `ui/vite.config.ts`: - Switch to the functional `defineConfig(({ mode }) => …)` form. - Add `build.minify: "esbuild"` (explicit — it's the existing default). - Add `esbuild.drop: ["console", "debugger"]` and `esbuild.legalComments: "none"`, gated on `mode === "production"` so `vite dev` is unaffected. ## Verification - `pnpm --filter @paperclipai/ui build` then grep the `ui/dist/assets/*.js` bundle for `console.log` — no occurrences. - `pnpm --filter @paperclipai/ui dev` — `console.log` calls in source still reach the browser console. - Bundle size: small reduction (varies with project but measurable on a fresh build). ## Risks Low. No API surface change. Production code should not depend on `console.*` for side effects; any call that did is now a dead call, which is the same behavior most minifiers apply. ## Model Used Claude Opus 4.6 (1M context), extended thinking mode. ## Checklist - [x] Thinking path traces from project context to this change - [x] Model used specified - [x] Tests run locally and pass - [x] CI green - [x] Greptile review addressed
2026-04-15 16:46:12 +02:00
export default defineConfig(({ mode }) => ({
plugins: [react(), tailwindcss()],
chore(ui): drop console.* and legal comments in production builds (#3728) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The web UI is a single-page app built with Vite and shipped as a static bundle to every deployment > - Production bundles carry `console.log` / `console.debug` calls from dev code and `/*! … */` legal-comment banners from third-party packages > - The console calls leak internals to anyone opening devtools and waste bytes per call site; the legal banners accumulate throughout the bundle > - Both problems affect every self-hoster, since they all ship the same UI bundle > - This pull request configures esbuild (via `vite.config.ts`) to strip `console` and `debugger` statements and drop inline legal comments from production builds only ## What Changed - `ui/vite.config.ts`: - Switch to the functional `defineConfig(({ mode }) => …)` form. - Add `build.minify: "esbuild"` (explicit — it's the existing default). - Add `esbuild.drop: ["console", "debugger"]` and `esbuild.legalComments: "none"`, gated on `mode === "production"` so `vite dev` is unaffected. ## Verification - `pnpm --filter @paperclipai/ui build` then grep the `ui/dist/assets/*.js` bundle for `console.log` — no occurrences. - `pnpm --filter @paperclipai/ui dev` — `console.log` calls in source still reach the browser console. - Bundle size: small reduction (varies with project but measurable on a fresh build). ## Risks Low. No API surface change. Production code should not depend on `console.*` for side effects; any call that did is now a dead call, which is the same behavior most minifiers apply. ## Model Used Claude Opus 4.6 (1M context), extended thinking mode. ## Checklist - [x] Thinking path traces from project context to this change - [x] Model used specified - [x] Tests run locally and pass - [x] CI green - [x] Greptile review addressed
2026-04-15 16:46:12 +02:00
build: {
minify: "esbuild",
},
esbuild:
mode === "production"
? {
drop: ["console", "debugger"],
legalComments: "none",
}
: undefined,
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
lexical: path.resolve(__dirname, "./node_modules/lexical/Lexical.mjs"),
},
},
server: {
port: 5173,
// WSL2 /mnt/ drives don't support inotify — fall back to polling so HMR works
watch: process.cwd().startsWith("/mnt/") ? { usePolling: true, interval: 1000 } : undefined,
proxy: {
"/api": {
target: "http://localhost:3100",
ws: true,
},
},
},
chore(ui): drop console.* and legal comments in production builds (#3728) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The web UI is a single-page app built with Vite and shipped as a static bundle to every deployment > - Production bundles carry `console.log` / `console.debug` calls from dev code and `/*! … */` legal-comment banners from third-party packages > - The console calls leak internals to anyone opening devtools and waste bytes per call site; the legal banners accumulate throughout the bundle > - Both problems affect every self-hoster, since they all ship the same UI bundle > - This pull request configures esbuild (via `vite.config.ts`) to strip `console` and `debugger` statements and drop inline legal comments from production builds only ## What Changed - `ui/vite.config.ts`: - Switch to the functional `defineConfig(({ mode }) => …)` form. - Add `build.minify: "esbuild"` (explicit — it's the existing default). - Add `esbuild.drop: ["console", "debugger"]` and `esbuild.legalComments: "none"`, gated on `mode === "production"` so `vite dev` is unaffected. ## Verification - `pnpm --filter @paperclipai/ui build` then grep the `ui/dist/assets/*.js` bundle for `console.log` — no occurrences. - `pnpm --filter @paperclipai/ui dev` — `console.log` calls in source still reach the browser console. - Bundle size: small reduction (varies with project but measurable on a fresh build). ## Risks Low. No API surface change. Production code should not depend on `console.*` for side effects; any call that did is now a dead call, which is the same behavior most minifiers apply. ## Model Used Claude Opus 4.6 (1M context), extended thinking mode. ## Checklist - [x] Thinking path traces from project context to this change - [x] Model used specified - [x] Tests run locally and pass - [x] CI green - [x] Greptile review addressed
2026-04-15 16:46:12 +02:00
}));