From 7b6f7ad2fb3cb720c80ba63ffefb3978e68755d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Thu, 16 Oct 2025 16:37:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(vscode):=20=E5=A2=9E=E5=BC=BA=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=B0=83=E8=AF=95=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 13 ++++++- .vscode/tasks.json | 54 +++++++++++++++++++---------- README-command.md | 73 +++++++++++++++++++++++++++++++++++++++ package.json | 33 ++++-------------- playwright.config.ts | 2 +- pnpm-lock.yaml | 3 -- vite.config.ts | 1 + worker-configuration.d.ts | 7 +--- 8 files changed, 129 insertions(+), 57 deletions(-) create mode 100644 README-command.md diff --git a/.vscode/launch.json b/.vscode/launch.json index 2213017..99c256f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,18 @@ "url": "http://localhost:4730/", "webRoot": "${workspaceFolder}", "firefoxExecutable": "/Applications/Firefox Nightly.app/Contents/MacOS/firefox", - "preLaunchTask": "🚀 dev" + "preLaunchTask": "🚀 dev", + "pathMappings": [ + { + "url": "http://localhost:4730", + "path": "${workspaceFolder}" + } + ], + "reAttach": true, + "reloadOnChange": { + "watch": "${workspaceFolder}/src/**/*.{js,jsx,ts,tsx,vue}", + "ignore": "**/node_modules/**" + } } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3d7ab16..ff4784d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,32 +2,48 @@ "version": "2.0.0", "tasks": [ { + "type": "npm", + "script": "dev", "label": "🚀 dev", - "type": "shell", - "command": "pnpm run dev", - "isBackground": true, + "detail": "启动开发服务器", "problemMatcher": { - "owner": "vite", - "pattern": { - "regexp": "." - }, + "pattern": { "regexp": "." }, "background": { "activeOnStart": true, - "beginsPattern": ".*VITE.*", - "endsPattern": ".*ready in.*" + "beginsPattern": "VITE.*ready in", + "endsPattern": "(Local|Network):.*http" } }, - "group": { - "kind": "build", - "isDefault": true + "isBackground": true, + "presentation": { "reveal": "always", "panel": "dedicated" }, + "group": { "kind": "build", "isDefault": false } + }, + { + "type": "npm", + "script": "build-only", + "label": "🔨 build-only", + "detail": "" /* 如果为空或省略,VSCode 将自动使用 package.json 中 scripts[scriptName] 的值作为 detail */, + "problemMatcher": ["$tsc"], + "presentation": { "reveal": "always", "panel": "shared" }, + "group": { "kind": "none", "isDefault": false } + }, + { + "type": "npm", + "script": "wrangler:dev", + "label": "☁️ wrangler:dev", + "detail": "启动 Cloudflare Workers 开发服务器,相当于预览", + "dependsOn": ["🔨 build-only"], + "problemMatcher": { + "pattern": { "regexp": "." }, + "background": { + "activeOnStart": true, + "beginsPattern": "wrangler dev", + "endsPattern": "Ready on" + } }, - "presentation": { - "reveal": "always", - "panel": "new" - }, - "runOptions": { - "instanceLimit": 1 - } + "isBackground": true, + "presentation": { "reveal": "always", "panel": "dedicated" }, + "group": { "kind": "build", "isDefault": false } } ] } diff --git a/README-command.md b/README-command.md new file mode 100644 index 0000000..64189ba --- /dev/null +++ b/README-command.md @@ -0,0 +1,73 @@ +## 依赖管理 + +```shell +pnpm dedupe +``` + +去除重复的依赖包。当你的项目中存在多个版本的同一个包时,pnpm dedupe 会尝试将它们合并成尽可能少的版本,从而减少 node_modules 的体积。 + +```bash +pnpm dlx taze major --interactive +``` + +交互式地将项目依赖升级到最新的主要版本,可以逐个选择要升级哪些包。 + +```bash +pnpm dlx knip +``` + +检测项目中未使用的依赖、导出和文件,帮助清理冗余代码。 + +## Playwright + +```bash +playwright test +``` + +- `HEADLESS=true`:强制无头模式 +- `--ui`:启动 Playwright 的图形用户界面,方便调试测试用例 +- `--project=chromium`:指定使用 Chromium 浏览器进行测试 +- `--quiet`:减少输出信息,只显示必要的内容 + +## Oxlint + +```bash +oxlint . --fix --ignore-path=.gitignore --print-config +``` + +```bash +oxlint . --fix --deny=correctness +``` + +## Wrangler + +### Pages + +```bash +wrangler pages deploy dist --project-name=vue-ts-example-2025 --branch=preview +``` + +```bash +wrangler pages deploy dist --project-name=vue-ts-example-2025 +``` + +### Workers + +```bash +wrangler deploy +``` + +```bash +wrangler versions upload +``` + +## 拆包体积分析 + +- https://github.com/nonzzz/vite-bundle-analyzer +- https://github.com/KusStar/vite-bundle-visualizer + +```bash +pnpm dlx vite-bundle-visualizer -t treemap +pnpm dlx vite-bundle-visualizer -t sunburst +pnpm dlx vite-bundle-visualizer -t network +``` diff --git a/package.json b/package.json index a1f31ed..754cedb 100644 --- a/package.json +++ b/package.json @@ -8,41 +8,21 @@ "node": "^20.19.0 || >=22.12.0" }, "scripts": { - "_all": "run-p build-only format type-check lint", + "_all": "run-p build-only format:prettier type-check lint test:unit:DisableWatch", "dev": "vite --port 4730 --host --strictPort", "build": "run-p type-check \"build-only {@}\" --", "build-only": "vite build", - "preview": "vite preview", - "preview:wrangler": "run-s build-only wrangler:dev", - "wrangler:dev": "wrangler dev", - "lint": "run-s lint:*", - "format": "prettier --write src/", + "preview": "vite preview --port 4731 --host --strictPort", + "wrangler:dev": "wrangler dev --port 4732", + "format:prettier": "prettier --write src/", "type-check": "vue-tsc --build", + "lint": "run-s lint:*", "lint:stylelint": "stylelint \"**/*.{css,less,scss,vue}\" --fix --ignore-path .gitignore", "lint:oxlint": "oxlint . --fix -D correctness --ignore-path .gitignore", "lint:eslint": "eslint . --fix", - "test:unit": "vitest", "test:unit:DisableWatch": "vitest --run", - "test:playwright": "playwright test", - "test:playwright:headless": "HEADLESS=true playwright test", - "test:playwright:ui": "playwright test --ui", - "test:playwright:chromium": "playwright test --project=chromium --quiet", - "_oxlint_cfg": "oxlint . --fix --ignore-path=.gitignore --print-config", - "__oxlint_-D": "oxlint . --fix --deny=correctness", - "-wrangler:pages:deploy:preview": "wrangler pages deploy dist --project-name=vue-ts-example-2025 --branch=preview", - "-wrangler:pages:deploy:prod": "wrangler pages deploy dist --project-name=vue-ts-example-2025", - "-deploy:preview": "run-s build-only wrangler:pages:deploy:preview", - "-deploy:prod": "run-s build-only wrangler:pages:deploy:prod", - "wrangler:deploy": "pnpm run build && wrangler deploy", - "wrangler:versions:upload": "pnpm run build && wrangler versions upload", - "cf-typegen": "wrangler types", + "test:playwright:headless": "HEADLESS=true playwright test --quiet", "postinstall": "wrangler types", - "_dep:dedupe": "pnpm dedupe", - "_dep:update": "pnpm dlx taze major --interactive", - "_sizecheck:Treemap": "pnpm dlx vite-bundle-visualizer -t treemap", - "_sizecheck:Sunburst": "pnpm dlx vite-bundle-visualizer -t sunburst", - "_sizecheck:Network": "pnpm dlx vite-bundle-visualizer -t network", - "_knip": "pnpm dlx knip", "prepare": "husky" }, "lint-staged": { @@ -108,7 +88,6 @@ "happy-dom": "^20.0.1", "html-minifier-terser": "^7.2.0", "husky": "^9.1.7", - "jiti": "^2.5.1", "jsdom": "^27.0.0", "lint-staged": "^16.1.6", "npm-run-all2": "^8.0.4", diff --git a/playwright.config.ts b/playwright.config.ts index 921416f..deb224e 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test'; import process from 'node:process'; // const runningInVSCode = process.env.TERM_PROGRAM === 'vscode' -const baseURL = 'http://localhost:4173'; +const baseURL = 'http://localhost:4731'; /** * Read environment variables from file. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e2f44ba..40e8ed0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -147,9 +147,6 @@ importers: husky: specifier: ^9.1.7 version: 9.1.7 - jiti: - specifier: ^2.5.1 - version: 2.6.1 jsdom: specifier: ^27.0.0 version: 27.0.0(postcss@8.5.6) diff --git a/vite.config.ts b/vite.config.ts index b192021..00a2610 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -73,6 +73,7 @@ export default defineConfig(({ command, mode }) => { }, }, css: { + devSourcemap: true, preprocessorOptions: { scss: { // 使用 Sass 的现代编译器 API,提供更好的性能和新功能支持 diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 52cc3f8..e703a8e 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// Generated by Wrangler by running `wrangler types` (hash: c8d566f9236103c3d936718f23f1bb71) +// Generated by Wrangler by running `wrangler types` (hash: 7094267439eea3789640d49ba1e25377) // Runtime types generated with workerd@1.20250927.0 2025-09-09 declare namespace Cloudflare { interface GlobalProps { @@ -7,11 +7,6 @@ declare namespace Cloudflare { } interface Env { KV: KVNamespace; - VITE_APP_TITLE: string; - VITE_APP_BASE: string; - VITE_APP_BUILD_SOURCE_MAP: string; - VITE_APP_BUILD_COMMIT: string; - VITE_APP_BUILD_TIME: string; } } interface Env extends Cloudflare.Env {}