| 编辑器 | 特点 | 适合人群 |
|---|---|---|
| VS Code | 功能强大,免费,插件丰富 | 推荐所有人 |
| Sublime Text | 轻量快速 | 喜欢简洁的开发者 |
| WebStorm | 专业强大,收费 | 专业前端开发者 |
VS Code 推荐插件:
3.1 官网下载
访问官网下载 LTS 版本
3.2 使用 nvm(Node 版本管理器)
Windows: https://github.com/coreybutler/nvm-windows
Mac/Linux: https://github.com/nvm-sh/nvm
3.3 Windows/Mac 安装后验证
node --version
npm --version
<!DOCTYPE html>
<html>
<head>
<title>我的第一个JS程序</title>
</head>
<body>
<h1 id="greeting">Hello World!</h1>
<button onclick="changeText()">点击我</button>
<script>
// 这里是JavaScript代码
function changeText() {
document.getElementById("greeting").innerHTML = "你好,JavaScript!";
}
</script>
</body>
</html>
# 创建项目目录
mkdir my-project
cd my-project
# 初始化 package.json
npm init -y
# 安装 webpack
npm install --save-dev webpack webpack-cli webpack-dev-server
# 安装 Babel(支持 ES6+)
npm install --save-dev @babel/core @babel/preset-env babel-loader
# 安装基础依赖
npm install --save-dev html-webpack-plugin clean-webpack-plugin
// webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "development",
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
devServer: {
static: "./dist",
hot: true,
open: true,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
],
};
// package.json scripts
{
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production",
"dev": "webpack --mode development"
}
}
# ESLint - 代码规范
npm install --save-dev eslint eslint-config-airbnb-base
# Prettier - 代码格式化
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier
# 初始化 ESLint 配置
npx eslint --init
# 使用 Parcel(零配置打包工具)
npm install -g parcel-bundler
parcel index.html
# 使用 Create React App(官方脚手架)
npx create-react-app my-app
cd my-app
npm start
# 使用 Vue CLI
npm install -g @vue/cli
vue create my-project
cd my-project
npm run serve
# Express 项目
npm init -y
npm install express
npm install --save-dev nodemon
# package.json
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
}
my-project/
├── src/
│ ├── index.html
│ ├── index.js
│ ├── styles/
│ └── components/
├── public/
├── dist/ # 构建输出目录
├── node_modules/
├── .gitignore
├── package.json
├── webpack.config.js
├── .eslintrc.js # ESLint 配置
├── .prettierrc # Prettier 配置
└── README.md
git init
git add .
git commit -m "Initial commit"