diff --git a/AGENTS.md b/AGENTS.md index 85c131b..8f97b2f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,8 +23,8 @@ npm run lint # ESLint with TypeScript strict rules ### Dual Build System -- **Website build**: `vite.config.ts` → React SPA with hash routing → `dist/` -- **Library build**: `vite.lib.config.ts` → UMD/ES modules → `dist/lib/` +- **Website build**: `vite.config.js` → React SPA with hash routing → `dist/` +- **Library build**: `vite.lib.config.js` → UMD/ES modules → `dist/lib/` - **Entry points**: `src/entry.ts` (library), `pages/main.tsx` (website) ### Module Boundaries (Critical) @@ -142,7 +142,7 @@ Query params configure `PageAgentConfig` automatically in `src/entry.ts`. - `src/dom/dom_tree/index.js` - DOM extraction engine - `src/utils/bus.ts` - Type-safe event bus system - `src/entry.ts` - Library entry point for CDN usage -- `vite.config.ts` / `vite.lib.config.ts` - Dual build configuration +- `vite.config.js` / `vite.lib.config.js` - Dual build configuration ## Debugging Common Issues diff --git a/eslint.config.js b/eslint.config.js index 61c1e7e..955f9fa 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -31,7 +31,7 @@ export default tseslint.config([ ], languageOptions: { parserOptions: { - project: ['./tsconfig.node.json', './tsconfig.app.json'], + project: ['./tsconfig.json'], tsconfigRootDir: import.meta.dirname, }, ecmaVersion: 2020, diff --git a/package-lock.json b/package-lock.json index bb3dbbc..a2d0715 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2538,6 +2538,7 @@ "integrity": "sha512-FYxk1I7wPv3K2XBaoyH2cTnocQEu8AOZ60hPbsyukMPLv5/5qr7V1i8PLHdl6Zf87I+xZXFvPCXYjiTFq+YSDQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.12.0" } @@ -2548,6 +2549,7 @@ "integrity": "sha512-WBM/nDbEZmDUORKnh5i1bTnAz6vTohUf9b8esSMu+b24+srbaxa04UbJgWx78CVfNXA20sNu0odEIluZDFdCog==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -2608,6 +2610,7 @@ "integrity": "sha512-TGf22kon8KW+DeKaUmOibKWktRY8b2NSAZNdtWh798COm1NWx8+xJ6iFBtk3IvLdv6+LGLJLRlyhrhEDZWargQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.45.0", "@typescript-eslint/types": "8.45.0", @@ -2872,6 +2875,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3339,6 +3343,7 @@ "integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "env-paths": "^2.2.1", "import-fresh": "^3.3.0", @@ -3535,6 +3540,7 @@ "dev": true, "hasInstallScript": true, "license": "MIT", + "peer": true, "bin": { "esbuild": "bin/esbuild" }, @@ -3599,6 +3605,7 @@ "integrity": "sha512-hB4FIzXovouYzwzECDcUkJ4OcfOEkXTv2zRY6B9bkwjx/cprAq0uvm1nl7zvQ0/TsUk0zQiN4uPfJpB9m+rPMQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -5747,6 +5754,7 @@ "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", "dev": true, "license": "MIT", + "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -5811,6 +5819,7 @@ "integrity": "sha512-w8nqGImo45dmMIfljjMwOGtbmC/mk4CMYhWIicdSflH91J9TyCyczcPFXJzrZ/ZXcgGRFeP6BU0BEJTw6tZdfQ==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -5930,6 +5939,7 @@ "integrity": "sha512-RIDh866U8agLgiIcdpB+COKnlCreHJLfIhWC3LVflku5YHfpnsIKigRZeFfMfCc4dVcqNVfQQ5gO/afOck064A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -6295,6 +6305,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -6390,6 +6401,7 @@ "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6568,6 +6580,7 @@ "integrity": "sha512-VbA8ScMvAISJNJVbRDTJdCwqQoAareR/wutevKanhR2/1EkoXVZVkkORaYm/tNVCjP/UDTKtcw3bAkwOUdedmA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -6671,6 +6684,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -6904,6 +6918,7 @@ "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.11.tgz", "integrity": "sha512-WPsqwxITS2tzx1bzhIKsEs19ABD5vmCVa4xBo2tq/SrV4RNZtfws1EnCWQXM6yh8bD08a1idvkB5MZSBiZsjwg==", "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index bfc6c87..daa68d6 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ "dev": "vite", "start": "vite", "build": "tsc -b && vite build && npm run build:lib && npm run build:umd", - "build:lib": "vite build --config vite.lib.config.ts", - "build:lib:watch": "vite build --config vite.lib.config.ts --watch", - "build:umd": "vite build --config vite.umd.config.ts", + "build:lib": "vite build --config vite.lib.config.js", + "build:lib:watch": "vite build --config vite.lib.config.js --watch", + "build:umd": "vite build --config vite.umd.config.js", "lint": "eslint .", "prepare": "husky" }, diff --git a/tsconfig.app.json b/tsconfig.app.json deleted file mode 100644 index 5bb0d28..0000000 --- a/tsconfig.app.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "compilerOptions": { - "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", - "target": "ES2022", - "useDefineForClassFields": true, - "lib": ["ES2022", "DOM", "DOM.Iterable", "ES2024"], - "module": "ESNext", - "skipLibCheck": true, - "allowJs": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": false, - "moduleDetection": "force", - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "erasableSyntaxOnly": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true, - - "baseUrl": "./", - "paths": { - "@/*": ["src/*"], - "@pages/*": ["pages/*"] - } - }, - "include": ["src", "pages", "env.d.ts"] -} diff --git a/tsconfig.json b/tsconfig.json index 88a659f..c538c0a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,34 @@ { - "files": [], - "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }] + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo", + "target": "ES2024", + "useDefineForClassFields": true, + "lib": ["ES2024", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + "allowJs": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": false, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "erasableSyntaxOnly": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true, + + "baseUrl": "./", + "paths": { + "@/*": ["src/*"], + "@pages/*": ["pages/*"] + } + }, + "include": ["src", "pages", "env.d.ts"] } diff --git a/tsconfig.node.json b/tsconfig.node.json deleted file mode 100644 index 60b118d..0000000 --- a/tsconfig.node.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", - "target": "ES2023", - "lib": ["ES2023"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "moduleDetection": "force", - "noEmit": true, - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "erasableSyntaxOnly": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true - }, - "include": ["vite.config.ts", "vite.lib.config.ts", "vite.umd.config.ts"] -} diff --git a/vite.config.ts b/vite.config.js similarity index 84% rename from vite.config.ts rename to vite.config.js index acea369..f7eb833 100644 --- a/vite.config.ts +++ b/vite.config.js @@ -1,3 +1,4 @@ +// @ts-check import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react-swc' import 'dotenv/config' @@ -9,8 +10,9 @@ import { defineConfig } from 'vite' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) -// https://vite.dev/config/ -export default defineConfig({ +/** @type {import('vite').UserConfig} */ +const config = { + // https://vite.dev/config/ base: './', plugins: [react(), tailwindcss()], resolve: { @@ -24,4 +26,6 @@ export default defineConfig({ 'import.meta.env.LLM_API_KEY': JSON.stringify(process.env.LLM_API_KEY), 'import.meta.env.LLM_BASE_URL': JSON.stringify(process.env.LLM_BASE_URL), }, -}) +} + +export default defineConfig(config) diff --git a/vite.lib.config.ts b/vite.lib.config.js similarity index 79% rename from vite.lib.config.ts rename to vite.lib.config.js index 23950af..d07837b 100644 --- a/vite.lib.config.ts +++ b/vite.lib.config.js @@ -1,3 +1,4 @@ +// @ts-check import { dirname, resolve } from 'path' import dts from 'unplugin-dts/vite' import { fileURLToPath } from 'url' @@ -7,10 +8,11 @@ import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) -// Library build configuration -export default defineConfig({ +/** @type {import('vite').UserConfig} */ +const config = { + // Library build configuration plugins: [ - dts({ tsconfigPath: './tsconfig.app.json', bundleTypes: true }), + dts({ tsconfigPath: './tsconfig.json', bundleTypes: true }), cssInjectedByJsPlugin({ relativeCSSInjection: true }), ], resolve: { @@ -36,8 +38,11 @@ export default defineConfig({ // minify: 'terser', minify: false, sourcemap: true, + cssCodeSplit: true, }, define: { 'process.env.NODE_ENV': '"production"', }, -}) +} + +export default defineConfig(config) diff --git a/vite.umd.config.ts b/vite.umd.config.js similarity index 81% rename from vite.umd.config.ts rename to vite.umd.config.js index 2e681b7..4addb67 100644 --- a/vite.umd.config.ts +++ b/vite.umd.config.js @@ -1,3 +1,4 @@ +// @ts-check import { dirname, resolve } from 'path' import { fileURLToPath } from 'url' import { defineConfig } from 'vite' @@ -6,8 +7,9 @@ import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) -// Library build configuration -export default defineConfig({ +/** @type {import('vite').UserConfig} */ +const config = { + // Library build configuration plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })], resolve: { alias: { @@ -26,8 +28,11 @@ export default defineConfig({ formats: ['umd'], }, outDir: resolve(__dirname, 'dist', 'umd'), + cssCodeSplit: true, }, define: { 'process.env.NODE_ENV': '"production"', }, -}) +} + +export default defineConfig(config)