当前位置: 首页 > news >正文

从 Node.js 安装到 Vue 3 开发环境搭建

我来为您提供一个在 Windows 10 系统上搭建 Vue 3 开发环境的详细教程。

一、安装 Node.js

1.1 下载 Node.js

  1. 访问 Node.js 官网:https://nodejs.org/
  2. 下载 LTS 版本(长期支持版,更稳定)
  3. 建议选择 .msi 安装包

1.2 安装步骤

  1. 双击下载的安装包
  2. 点击 “Next” 进入下一步
  3. 接受协议,点击 “Next”
  4. 选择安装路径(建议默认路径)
  5. 选择安装组件(保持默认即可)
  6. 点击 “Install” 开始安装
  7. 安装完成后点击 “Finish”

1.3 验证安装

打开命令提示符(Win+R,输入 cmd)或 PowerShell,输入:

node -v
npm -v

如果显示版本号,说明安装成功。

二、配置 npm 镜像源

2.1 配置淘宝镜像源(推荐)

方法一:直接设置 npm 镜像
# 设置淘宝镜像
npm config set registry https://registry.npmmirror.com# 验证是否设置成功
npm config get registry
方法二:使用 cnpm(淘宝 npm 镜像)
# 全局安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com# 使用 cnpm 代替 npm
cnpm -v

2.2 其他常用国内镜像源

# 腾讯云镜像
npm config set registry https://mirrors.cloud.tencent.com/npm/# 华为云镜像
npm config set registry https://repo.huaweicloud.com/repository/npm/# 阿里云镜像
npm config set registry https://registry.npmmirror.com# 切换回官方源
npm config set registry https://registry.npmjs.org/

2.3 使用 nrm 管理镜像源(推荐)

# 全局安装 nrm
npm install -g nrm# 查看可用镜像源
nrm ls# 切换镜像源
nrm use taobao  # 使用淘宝镜像
nrm use npm     # 切回官方源# 测试镜像源速度
nrm test# 查看当前使用的镜像源
nrm current

三、配置私服镜像源

3.1 配置企业私服(以 Nexus 为例)

# 设置私服地址
npm config set registry http://your-nexus-server:8081/repository/npm-group/# 设置认证信息
npm config set always-auth true
npm config set _auth "用户名:密码的base64编码"# 或者使用 npm login
npm login --registry=http://your-nexus-server:8081/repository/npm-group/

3.2 配置 .npmrc 文件

在项目根目录或用户目录创建 .npmrc 文件:

# 默认镜像源
registry=https://registry.npmmirror.com/# 私服配置
@company:registry=http://your-nexus-server:8081/repository/npm-group/# 认证信息
//your-nexus-server:8081/repository/npm-group/:_authToken=YOUR_TOKEN# 特定包的镜像源
sass_binary_site=https://npmmirror.com/mirrors/node-sass/
electron_mirror=https://npmmirror.com/mirrors/electron/

四、安装 Vue 3 脚手架

4.1 安装 Vue CLI(传统方式)

# 全局安装 Vue CLI
npm install -g @vue/cli# 验证安装
vue --version# 创建 Vue 3 项目
vue create my-vue3-project# 选择 Vue 3 preset

4.2 使用 Vite(推荐,更快速)

# 使用 npm
npm create vite@latest my-vue3-app -- --template vue# 使用 yarn
yarn create vite my-vue3-app --template vue# 使用 pnpm
pnpm create vite my-vue3-app --template vue# 进入项目目录
cd my-vue3-app# 安装依赖
npm install# 启动开发服务器
npm run dev

4.3 使用 create-vue(官方推荐)

# 创建项目
npm create vue@latest# 按提示选择配置:
# ✔ Project name: … my-vue3-project
# ✔ Add TypeScript? … No / Yes
# ✔ Add JSX Support? … No / Yes
# ✔ Add Vue Router for Single Page Application development? … No / Yes
# ✔ Add Pinia for state management? … No / Yes
# ✔ Add Vitest for Unit Testing? … No / Yes
# ✔ Add an End-to-End Testing Solution? › No
# ✔ Add ESLint for code quality? … No / Yes
# ✔ Add Prettier for code formatting? … No / Yes# 进入项目并安装依赖
cd my-vue3-project
npm install
npm run dev

五、安装 Vue 开发常用包

5.1 核心库

# Vue Router(路由)
npm install vue-router@4# Pinia(状态管理,Vuex 的替代品)
npm install pinia# Vuex(传统状态管理)
npm install vuex@next

5.2 UI 组件库

# Element Plus
npm install element-plus# Ant Design Vue
npm install ant-design-vue@next# Vant 4(移动端)
npm install vant# Naive UI
npm install naive-ui# Arco Design Vue
npm install @arco-design/web-vue

5.3 开发工具

# Axios(HTTP 请求)
npm install axios# Sass/Scss
npm install -D sass# Less
npm install -D less# TypeScript
npm install -D typescript @vue/tsconfig# ESLint + Prettier
npm install -D eslint prettier eslint-plugin-vue eslint-config-prettier# Tailwind CSS
npm install -D tailwindcss postcss autoprefixer# VueUse(组合式 API 工具集)
npm install @vueuse/core

5.4 构建优化工具

# 自动导入
npm install -D unplugin-auto-import unplugin-vue-components# 图标
npm install -D unplugin-icons @iconify/json# 压缩
npm install -D vite-plugin-compression# 打包分析
npm install -D rollup-plugin-visualizer

六、项目配置示例

6.1 package.json 示例

{"name": "my-vue3-app","version": "0.1.0","scripts": {"dev": "vite","build": "vite build","preview": "vite preview","lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore","format": "prettier --write ."},"dependencies": {"vue": "^3.4.0","vue-router": "^4.2.5","pinia": "^2.1.7","axios": "^1.6.0","element-plus": "^2.4.0"},"devDependencies": {"@vitejs/plugin-vue": "^5.0.0","vite": "^5.0.0","sass": "^1.69.0","eslint": "^8.56.0","prettier": "^3.1.0"}
}

6.2 vite.config.js 配置

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'export default defineConfig({plugins: [vue()],resolve: {alias: {'@': path.resolve(__dirname, 'src')}},server: {port: 3000,host: '0.0.0.0',proxy: {'/api': {target: 'http://localhost:8080',changeOrigin: true,rewrite: (path) => path.replace(/^\/api/, '')}}}
})

七、常见问题解决

7.1 npm 安装速度慢

# 清除缓存
npm cache clean --force# 使用淘宝镜像
npm config set registry https://registry.npmmirror.com

7.2 权限问题

# 以管理员身份运行 PowerShell
# 设置执行策略
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

7.3 版本管理

# 安装 nvm-windows(Node 版本管理器)
# 下载地址:https://github.com/coreybutler/nvm-windows# 使用 nvm 管理 Node 版本
nvm list available  # 查看可用版本
nvm install 18.19.0  # 安装指定版本
nvm use 18.19.0     # 使用指定版本
nvm list            # 查看已安装版本

八、快速启动脚本

创建一个 setup.bat 文件,一键配置环境:

@echo off
echo 正在配置 Vue 开发环境...REM 配置淘宝镜像
call npm config set registry https://registry.npmmirror.com
echo npm 镜像已配置为淘宝镜像REM 安装全局工具
call npm install -g @vue/cli
call npm install -g create-vite
call npm install -g nrm
echo 全局工具安装完成REM 创建 Vue 3 项目
call npm create vue@latest my-vue3-appecho 环境配置完成!
pause

这个教程涵盖了从 Node.js 安装到 Vue 3 开发环境搭建的完整流程。根据实际需求,您可以选择性地安装和配置相关工具和包。


文章转载自:

http://VI8EuSbo.hqLLx.cn
http://fHQkPhWe.hqLLx.cn
http://hWjif3Ew.hqLLx.cn
http://7w2wlh0y.hqLLx.cn
http://N2OrHuDm.hqLLx.cn
http://lfBzzgfA.hqLLx.cn
http://CRGgEQrN.hqLLx.cn
http://YfjdaMFq.hqLLx.cn
http://qdIC6ihV.hqLLx.cn
http://REmPUTY0.hqLLx.cn
http://Zkawhaw0.hqLLx.cn
http://dVE2YlxX.hqLLx.cn
http://iZJM78S1.hqLLx.cn
http://gKWtPXSy.hqLLx.cn
http://7MEqXqBe.hqLLx.cn
http://gL9OVhNK.hqLLx.cn
http://UBJbsER0.hqLLx.cn
http://TasXQM4Z.hqLLx.cn
http://5jSRhSjc.hqLLx.cn
http://zUl0U4uH.hqLLx.cn
http://nqHMXNiA.hqLLx.cn
http://eIM6fXpA.hqLLx.cn
http://jE0LDLDm.hqLLx.cn
http://KoTWDmgQ.hqLLx.cn
http://TzhCkXvS.hqLLx.cn
http://JemLbkk7.hqLLx.cn
http://a4ulF8Gx.hqLLx.cn
http://iNDhH8ot.hqLLx.cn
http://9Ied17FL.hqLLx.cn
http://rwXjxC4b.hqLLx.cn
http://www.dtcms.com/a/386276.html

相关文章:

  • Python单元测试框架之pytest -- 生成测试报告
  • 使用HBuilderX新建uniapp项目
  • 医疗行业安全合规数据管理平台:构建高效协作与集中化知识沉淀的一体化解决方案
  • 从一次鼠标点击窥探操作系统内核:中断、驱动、IPC与内存安全的奇幻之旅
  • 【超详细】C#的单例模式
  • 加快 NoETL 数据工程实践, Aloudata 荣登《2025 中国数智化转型升级创新服务企业》榜单
  • 香港服务器CN2带宽价格多少钱?很贵吗?
  • 180 课时吃透 Go 语言游戏后端系列1:第一个Go程序
  • MSI 与 IOAPIC LAPIC 如何协作,操作系统如何初始化和使用他们
  • 数据库优化(六)安全字段脱敏设计—东方仙盟金丹期
  • java21学习笔记
  • 大厂综合题库解析
  • 算法奇妙屋(2)-模拟
  • 贪心算法应用:区间调度问题详解
  • js中异步编程的实现方式【详细】
  • 详解 ArduPilot:开源无人机自动驾驶系统的全方位解析
  • 分页查询:时间筛选+日期筛选+增加queryWrapper 筛选条件
  • 通透理清三级缓存--看Spring是如何解决循环依赖的
  • 【08】AI辅助编程完整的安卓二次商业实战-修改消息聊天框背景色-触发聊天让程序异常终止bug牵涉更多聊天消息发送优化处理-优雅草卓伊凡
  • 查看 Docker 守护进程日志
  • 第11章 [特殊字符]️Hutool 常用工具类
  • 【MySQL|第十篇】总结篇——各种命令集合
  • npm : 无法加载文件 d:\nvm4w\nodejs\npm.ps1,
  • 贪心算法应用:活动选择问题详解
  • C++ 模板:以简御繁-5/5
  • AI大模型学习(6)Yolo V8神经网络的基础应用
  • 【完整源码+数据集+部署教程】残疾人和正常人识别图像分割系统: yolov8-seg-act
  • 深度学习:从概念到实践,开启智能时代新篇章
  • 构建AI智能体:三十五、决策树的核心机制(一):刨根问底鸢尾花分类中的参数推理计算
  • 美创科技入选 2025 年度省级场景型数字化服务商!