安装vue3.0脚手架

1、安装vue-cli 3.0

先卸载旧版本

npm uninstall vue-cli -g

安装3.0脚手架

npm install -g @vue/cli
# or
yarn global add @vue/cli

安装成功查看版本 vue-V
如果出现安装失败或者提示errno 4048,是权限问题,使用管理员身份执行,记得重复2,3两步(多试几遍就好了)
在这里插入图片描述

vue3.0脚手架搭建

1、安装vue-cli 3.0

先卸载旧版本

npm uninstall vue-cli -g

安装3.0脚手架

npm install -g @vue/cli
# or
yarn global add @vue/cli

安装成功查看版本 vue-V
如果出现安装失败或者提示errno 4048,是权限问题,使用管理员身份执行,记得重复2,3两步(多试几遍就好了)

在这里插入图片描述

2.创建项目

1)去你想要指定目录下创建项目
test:项目名称

vue create health

2)项目配置:我选择自定义配置
在这里插入图片描述
3)接下来就是选择我们所需的选项来生成项目,使用 空格键 选中

? Check the features needed for your project:
 (*) Choose Vue version                       //选择版本3.x还是2.x
 (*) Babel                                    // javascript转译器
 (*) TypeScript                               // 使用 TypeScript 书写源码
 ( ) Progressive Web App (PWA) Support        // 渐进式WEB应用
 (*) Router                                   // 使用vue-router
 (*) Vuex                                     // 使用vuex
 (*) CSS Pre-processors                       // 使用css预处理器
>(*) Linter / Formatter                       // 代码规范标准
 ( ) Unit Testing                             // 单元测试
 ( ) E2E Testing                              // e2e测试

4)选择版本 3.x的

? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, TS, Router, Vuex, CSS Pre-processors, Linter
? Choose a version of Vue.js that you want to start the project with
  2.x
> 3.x

5)是否使用Class风格装饰器?

即原本是:home = new Vue()创建vue实例
使用装饰器后:class home extends Vue{}

? Use class-style component syntax? (y/N) y

6)使用Babel与TypeScript一起用于自动检测的填充 ?

? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? (Y/n) Y

7)路由模式

 Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) Y

8)我选择 Sass/SCSS (with dart-sass)

? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys)
> Sass/SCSS (with dart-sass) // 保存后编译
  Sass/SCSS (with node-sass) // 实时编译 
  Less
  Stylus

9)选择 代码格式化检测 因为是用typescript 所以选择 TSLint

? Pick a linter / formatter config: (Use arrow keys)
> ESLint with error prevention only // 只进行报错提醒
  ESLint + Airbnb config // 不严谨模式
  ESLint + Standard config // 正常模式
  ESLint + Prettier  // 严格模式
  TSLint (deprecated)  // typescript格式验证工具

10)代码检查方式 保存检查

? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)
>(*) Lint on save //保存就检测
 ( ) Lint and fix on commit //fix和commit就检测

11) 文件配置,我选择配置在独立的文件中

? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)
> In dedicated config files  //独立文件存放
  In package.json //放到package里面

12)保存上述配置,保存后下一次可直接根据上述配置生成项目,这里我就不保存了,有需要的同学可自行保存

? Save this as a preset for future projects? (y/N) N

完整的配置

Vue CLI v4.5.13
Failed to check for updates
? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, TS, Router, Vuex, CSS Pre-processors, Linter
? Choose a version of Vue.js that you want to start the project with 3.x
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
? Pick a linter / formatter config: TSLint
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? (y/N) N

OK,等待项目加载各种包…

报错了

Error: Cannot find module 'vue-template-compiler'

解决办法

cd health

npm install vue-template-compiler

npm run serve

这时我们的项目就已经生成并启动完成;默认是localhost:8080

看下项目目录结构
在这里插入图片描述

<think>嗯,用户想从零开始搭建Vue 3.0脚手架,需要教程和初始化项目配置。首先,我得回顾一下Vue 3.0脚手架搭建步骤。根据之前的引用内容,用户提到的引用里提到了使用vue-cli和Vite两种方式。比如引用[1]和[4]提到vue-cli,而引用[2]用的是Vite。所以应该先比较这两种工具的区别,然后分别给出步骤。 用户可能不太清楚vue-cli和Vite的区别,需要解释一下。Vite是新的构建工具,启动更快,适合现代浏览器项目,而vue-cli是传统的脚手架,生态更成熟。可能用户需要根据项目需求选择,所以教程里应该包含两种方法。 然后,具体步骤。对于vue-cli,首先需要安装Node.js和npm,然后全局安装@vue/cli,接着用vue create命令创建项目,选择Vue 3预设。过程中可能需要配置选项,比如Babel、Router等,但用户可能希望简单,所以默认配置可能更合适。安装完成后,运行npm run serve启动项目。 对于Vite的方法,引用[2]和[4]提到使用npm create vite@latest,然后选择vue模板。这种方法更快速,适合追求效率的用户。步骤包括创建项目、安装依赖、启动服务。需要提醒用户Vite的优势,比如更快的热更新。 另外,用户可能遇到安装问题,比如网络慢,需要配置淘宝镜像。引用[4]提到用npm config set registry来换源,这个步骤应该包含在环境准备里。还有初始化项目后的目录结构,可能需要简单说明,让用户知道生成的文件和文件夹的作用。 初始化项目配置可能涉及添加插件或UI库,比如Element Plus,如引用[2]中的例子。用户可能想知道如何集成这些,但问题主要是搭建脚手架,所以这部分可以作为扩展内容,或者在相关问题里提到。 需要检查每个步骤的命令是否正确,比如vue create和npm create vite的区别,确保用户复制命令时不会出错。还要注意项目名称是否有效,不能有大写或特殊字符,这点需要提醒用户。 最后,生成相关问题,可以围绕两种工具的区别、优化配置、常见问题、插件集成等,帮助用户进一步学习。</think>### Vue 3.0 脚手架搭建教程 #### 一、环境准备 1. **安装Node.js** -安装Node.js 14.18+ 或 16+ 版本(Vue 3.0要求) - 验证安装:终端输入 `node -v` 和 `npm -v` 查看版本[^1][^4] 2. **配置镜像源(可选)** ```bash npm config set registry https://registry.npm.taobao.org ``` --- #### 二、脚手架搭建方法 **▋ 方法1:使用Vue CLI(传统方式)** ```bash # 全局安装脚手架工具 npm install -g @vue/cli # 创建项目 vue create vue3-demo ``` - 选择预设: - 方向键选择 `Vue 3` 默认配置[^5] - 按回车确认依赖包安装 **▋ 方法2:使用Vite(推荐)** ```bash # 快速创建项目 npm create vite@latest vue3-vite-demo -- --template vue # 安装依赖 cd vue3-vite-demo npm install ``` --- #### 三、项目初始化配置 1. **目录结构** 生成的核心文件: ``` ├── src/ # 源码目录 │ ├── main.js # 入口文件(Vue实例初始化) │ └── App.vue # 根组件 ├── package.json # 依赖配置 └── vite.config.js # Vite专属配置[^2] ``` 2. **启动开发服务器** ```bash npm run dev # Vite项目 # 或 npm run serve # Vue CLI项目 ``` 访问 `http://localhost:3000` 查看初始页面[^3] --- #### 四、扩展配置(可选) 1. **集成Element Plus** ```bash npm install element-plus --save ``` 在 `main.js` 中添加: ```javascript import ElementPlus from &#39;element-plus&#39; import &#39;element-plus/dist/index.css&#39; createApp(App).use(ElementPlus).mount(&#39;#app&#39;) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值