萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

HTML 編輯實戰指南:從記事本到專業 IDE 的工具鏈與工作流

編輯 HTML 的三種層次

層次工具代表優點缺點適用階段
純文本編輯器Notepad (Win)、TextEdit (Mac)、Nano/Vim (Term)零依賴、啟動極快、任何系統可用無高亮、無提示、無格式化、無預覽、易出錯極簡環境、臨時修改、教學演示「本質」
代碼編輯器VS Code、Sublime Text、Notepad++、Zed、Neovim語法高亮、Emmet、智能提示、格式化、Git 整合、終端、擴展生態、Live Preview需安裝配置、Electron 類佔內存**現代前端開發主流選擇**
專業 IDEWebStorm、PhpStorm、IntelliJ IDEA、Visual Studio深度靜態分析、重構、測試運行器、資料庫工具、框架深度整合、團隊協作功能收費(訂閱制)、啟動較慢、資源佔用高大型項目、企業級開發、全棧、重構密集

新手「四步走」創建首個網頁(以 VS Code 為例)

  1. 安裝 VS Code → 安裝擴展:Live Server、Prettier、HTML CSS Support、Auto Rename Tag。
  2. 創建項目資料夾 → `mkdir my-first-page && cd my-first-page && code .`
  3. 新建 index.html → 輸入 `!` 按 Tab (Emmet) 生成骨架 → 填充內容:
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>我的第一個網頁</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Hello, HTML!</h1>
  <p>這是我手寫的第一個網頁。</p>
</body>
</html>
  1. 實時預覽: 右鍵編輯器 →「Open with Live Server」→ 瀏覽器自動打開 `https://127.0.0.1:5500`,保存即刷新。

進階工作流:專業級工具鏈

1. 代碼質量保障

# 項目根目錄
npm init -y
npm i -D eslint @eslint/js htmlhint stylelint prettier husky lint-staged

# .eslintrc.cjs
module.exports = { root:true, env:{browser:true, es2022:true}, extends:['eslint:recommended'], parserOptions:{ecmaVersion:'latest'} }

# .htmlhintrc
{ "tagname-lowercase": true, "attr-lowercase": true, "attr-value-double-quotes": true, "doctype-first": true, "tag-pair": true, "spec-char-escape": true, "id-unique": true, "src-not-empty": true, "alt-require": true, "head-script-disabled": true, "style-disabled": true }

# .stylelintrc.cjs
module.exports = { extends:['stylelint-config-standard'], rules:{'color-hex-case':'lower','color-hex-length':'short'} }

# .prettierrc
{ "printWidth":120, "tabWidth":2, "useTabs":false, "singleQuote":true, "htmlWhitespaceSensitivity":"css" }

# package.json scripts
"lint": "eslint . && htmlhint **/*.html && stylelint **/*.css",
"format": "prettier --write .",
"prepare": "husky install"

2. Git Hooks 自動化

npx husky add .husky/pre-commit "npx lint-staged"
# .lintstagedrc
{
  "*.{html,js,ts,jsx,tsx,vue,svelte}": ["prettier --write", "eslint --fix"],
  "*.css": ["prettier --write", "stylelint --fix"]
}

3. 組件化開發(可選)

  • Vite + Vue/React/Svelte/Astro:單文件組件(SFC)封裝 HTML/CSS/JS。
  • Web Components 原生:`