「工欲善其事,必先利其器」。良好的開發環境能提升 50%+ 效率。本課涵蓋編輯器選型、瀏覽器開發者工具、本地服務器、版本控制、代碼規範工具鏈。
| 分類 | 擴展名稱 | 作用 |
|---|---|---|
| 核心增強 | Chinese (Traditional) Language Pack | 繁中介面 |
| HTML/CSS | HTML CSS Support | 類名/ID 智能提示、Emmet 增強 |
| Live Server | 一鍵啟動本地服務器、熱重載 | |
| Prettier | 保存自動格式化 (需配置 .prettierrc) | |
| JS/TS | JavaScript (ES6) code snippets | 常用代碼片段 |
| ESLint | 靜態檢查、規範風格 | |
| Git | GitLens | 行級提交歷史、責任人、對比 |
| 效率 | Auto Rename Tag / Path Intellisense / Bracket Pair Colorizer | 重命名標籤、路徑補全、括號著色 |
直接雙擊 HTML 會觸發:跨域限制、Cookie 無效、Service Worker 失效、ES Module 報錯。
| 方案 | 啟動命令 | 特點 | 適用場景 |
|---|---|---|---|
| VS Code Live Server | 右鍵「Open with Live Server」 | 零配置、熱重載、HTTPS 支援 | 入門、靜態頁面 |
| Node http-server | `npx http-server -p 3000 -c-1` | 命令行、可配置緩存、SPA 回退 | 簡單靜態站點 |
| Vite | `npm create vite@latest` → `npm run dev` | 極速冷啟動、HMR、TS/JSX/PostCSS 開箱即用 | 現代前端項目首選 |
| Webpack DevServer | `npx webpack serve` | 功能全、配置複雜、生態豐富 | 大型遺留項目 |
# 初始化
git init
git add .
git commit -m "feat: 初始化項目結構"
# 分支策略 (Git Flow 簡化版)
git checkout -b dev # 開發分支
git checkout -b feat/login # 功能分支
# 開發...
git add . && git commit -m "feat: 實現登錄頁面"
git checkout dev && git merge feat/login
# 發布
git checkout main && git merge dev && git tag v1.0.0
# .prettierrc
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "es5"
}
# .eslintrc.js (基於 eslint:recommended + plugin:vue/recommended + @typescript-eslint/recommended)
module.exports = {
root: true,
env: { browser: true, es2022: true, node: true },
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
rules: {
'no-console': 'warn',
'no-debugger': 'warn',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }]
}
}
# package.json scripts
{
"scripts": {
"lint": "eslint . --ext .js,.ts,.vue",
"lint:fix": "eslint . --ext .js,.ts,.vue --fix",
"format": "prettier --write ."
}
}
配合 VS Code `editor.formatOnSave: true`、`editor.codeActionsOnSave: { "source.fixAll.eslint": true }` 實現保存即格式化+修復。