1、需要NodeJS环境支持,此处省略NodeJS安装

2、使用NPM命令安装CLI包

vue-cli是npm.上的一个全局包,使用npm install 命令,即可方便的把它安装到自己的电脑上:

npm install -g @vue/cli

命令输出:

C:\Users\Administrator>npm install -g @vue/cli
npm WARN deprecated graphql-tools@4.0.8: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
npm WARN deprecated subscriptions-transport-ws@0.9.19: The `subscriptions-transport-ws` package is no longer maintained. We recommend you use `graphql-ws` instead. For help migrating Apollo software to `graphql-ws`, see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws For general help using `graphql-ws`, see https://github.com/enisdenjo/graphql-ws/blob/master/README.md
npm WARN deprecated apollo-cache-control@0.14.0: The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.
npm WARN deprecated graphql-extensions@0.15.0: The `graphql-extensions` API has been removed from Apollo Server 3. Use the plugin API instead: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
npm WARN deprecated apollo-tracing@0.15.0: The `apollo-tracing` package is no longer part of Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#tracing for details
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
C:\Users\Administrator\AppData\Roaming\npm\vue -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\@vue\cli\bin\vue.js > core-js-pure@3.22.3 postinstall C:\Users\Administrator\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}" Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library! The project needs your help! Please consider supporting of core-js:
> https://opencollective.com/core-js
> https://patreon.com/zloirock
> bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -) > @apollo/protobufjs@1.2.2 postinstall C:\Users\Administrator\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\@apollo\protobufjs
> node scripts/postinstall npm WARN node-fetch@2.6.7 requires a peer of encoding@^0.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.7 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.7 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself. + @vue/cli@5.0.4
added 883 packages from 531 contributors in 49.297s C:\Users\Administrator>

3、使用CLI命令创建项目

指定项目名称(demo-first):

vue create demo-first

选择初始化模板种类:

这里选择手动配置

Vue CLI v5.0.4
? Please pick a preset: (Use arrow keys) -- 使用方向键进行选择
Default ([Vue 3] babel, eslint) -- Vue3 项目 配置ESlint 和Babel加载器
Default ([Vue 2] babel, eslint) -- Vue2 项目 配置ESlint 和Babel加载器
> Manually select features -- 手动选择特性

选择需要安装的组件和插件支持

勾选Babel加载器和CSS预处理器

Vue CLI v5.0.4
? Please pick a preset: Manually select features
? Check the features needed for your project:
(
Press <space> to select, -- 按空格选中
<a> to toggle all, -- 按A全选
<i> to invert selection, -- 按i反选
and <enter> to proceed -- 按回车执行
)
>(*) Babel -- Babel加载器
( ) TypeScript -- TS脚本
( ) Progressive Web App (PWA) Support -- 渐进式WEB框架
( ) Router -- Vue路由配置
( ) Vuex -- Vue叉 集中缓存配置
(*) CSS Pre-processors -- CSS样式预处理器 LESS、SASS
( ) Linter / Formatter -- 语法限制
( ) Unit Testing -- 单元测试
( ) E2E Testing -- E2E测试

版本选择单独拎出来了,这里选择Vue2版本

 ? Choose a version of Vue.js that you want to start the project with
3.x
> 2.x

CSS预处理器的选择:

? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys)
> Sass/SCSS (with dart-sass)
Less
Stylus

配置文件的管理方式选择:

选择独立配置文件,不要选择集中在package.json中管理

一个组件对应一个配置文件

? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)
> In dedicated config files -- 独立配置文件
In package.json -- 统一在package.json

 

最后是否保存上述选择作为一个自定义创建模板

方便下次创建时使用

# 是否保存这些预设作为创建模板?
? Save this as a preset for future projects? (y/N)

 

保存时指定模板名称:

# 保存命名:
? Save preset as:

依赖构建工具选择:

YARN或者NPM,这里选择NPM

# 依赖构建选择哪种工具, Yarn, NPM
选择NPM, 然后自动下载依赖
? Pick the package manager to use when installing dependencies: (Use arrow keys)
> Use Yarn
Use NPM

构建完成时输出:

# 项目构建完成
Vue CLI v5.0.4
Creating project in G:\frontend-note\Stage6 Vue\demo-first.
⚙️ Installing CLI plugins. This might take a while... > core-js@3.22.3 postinstall G:\frontend-note\Stage6 Vue\demo-first\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}" added 829 packages from 460 contributors in 85.615s
Invoking generators...
Installing additional dependencies... added 17 packages from 15 contributors in 6.856s
Running completion hooks... Generating README.md... Successfully created project demo-first.
Get started with the following commands: $ cd demo-first
$ npm run serve PS G:\frontend-note\Stage6 Vue>

 

创建成功会提示如何运行这个项目模板:

  Successfully created project demo-first.
Get started with the following commands: $ cd demo-first
$ npm run serve

模板目录结构:

Name
----
node_modules - 构建依赖
public
- favor.ico 标签 logo
- index.html 首页
src - 源码目录
- assets文件夹:存放项目中用到的静态资源文件,例如: ess样式表、图片资源
- components文件夹: 程序员封装的、可复用的组件,都要放到components目录下
- main.js是项目的入口文件。整个项目的运行,要先执行main.js
- App.vue是项目的根组件。
.browserslistrc
.gitignore
babel.config.js
jsconfig.json
package-lock.json
package.json
README.md
vue.config.js

 

在工程化的项目中,vue要做的事情很单纯:

通过|main.js|把App.vue渲染到index.html的指定区域中。

 

【Vue2】Vue-Cli使用的更多相关文章

  1. Vue CLI创建Vue2项目

    1.安装Node.js * Node.js中包含了npm工具 安装后查看版本: node -v npm -v 2.设置npm的源为国内源 npm config set registry https:/ ...

  2. 13. Vue CLI脚手架

    一. Vue CLI 介绍 1. 什么是Vue CLI? Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统.Vue CLI 致力于将 Vue 生态中的工具基础标准化.它确保了各种构建工 ...

  3. Vue CLI 是如何实现的 -- 终端命令行工具篇

    Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统,提供了终端命令行工具.零配置脚手架.插件体系.图形化管理界面等.本文暂且只分析项目初始化部分,也就是终端命令行工具的实现. 0. 用法 ...

  4. Vue CLI 5 和 vite 创建 vue3.x 项目以及 Vue CLI 和 vite 的区别

    这几天进入 Vue CLI 官网,发现不能选择 Vue CLI 的版本,也就是说查不到 vue-cli 4 以下版本的文档. 如果此时电脑上安装了 Vue CLI,那么旧版安装的 vue 项目很可能会 ...

  5. vue cli 3.x 项目部署到 github pages

    github pages 是 github 免费为用户提供的服务,写博客,或者部署一些纯静态项目. 最近将 vue cli 3.x 初始化项目部署到 github pages,踩了一些坑,记录如下. ...

  6. @vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件

    目录 @vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件 运行 使用 配置 svg-sprite-loader 调用当前环境下的颜色 props @vue/cl ...

  7. vue cli使用融云实现聊天

    公司有个项目要实现一个聊天功能,需求如下图,略显随意 公司最终选择融云这个吊炸天的即时通信,文档详细的一匹,刚开始看文档感觉很详细实现起来也不麻烦,有很多开源的demo可以在线演示和下载 不过我们的项 ...

  8. Vue CLI 3.0脚手架如何在本地配置mock数据

    前后端分离的开发模式已经是目前前端的主流模式,至于为什么会前后端分离的开发我们就不做过多的阐述,既然是前后端分离的模式开发肯定是离不开前端的数据模拟阶段. 我们在开发的过程中,由于后台接口的没有完成或 ...

  9. Vue CLI 3使用:浏览器兼容性

    package.json 文件里的 browserslist 字段 (或一个单独的 .browserslistrc 文件),指定了项目的目标浏览器的范围.这个值会被 @babel/preset-env ...

  10. 基于vue cli 3.0创建前端项目并安装cube-ui

    前提条件: 安装node.js. 国内的开发者最好先配置淘宝镜像. 之后用cnpm来代替npm命令. 项目创建过程: 打开cmd,输入命令进入目标工作空间,以本机项目为例: cd /d d: cd D ...

随机推荐

  1. uniapp SyntaxError: Unexpected token u in JSON at position 0 解决方案

    今天在做页面跳转传值的时候,一直出现下面的报错: 后来查看了下文档,说如果你的JSON数据是在上一个页面传值过来的话, 这时候在接收数据页解析JSON也会报该错误,因为此时并没有相关的JSON数据从上 ...

  2. python+k8s(基础,遇到的问题)

    python+k8s(基础,遇到的问题) CoreV1Api和ApiClient的区别 kubernetes.client.CoreV1Api kubernetes.client.ApiClient ...

  3. .NET8 Hello World!

    ​ 使用ASP.NET Core Web Application模板创建的Empty项目如下: ​ 这是一个最简单的Web项目,运行起来会在根路径响应Hello World! 2.1.1 Progra ...

  4. react mock数据

    为什么要做假数据,因为后端开发接口没有哪么快,此时就需要自己来模拟请求数据. 模拟的数据字段,需要和后端工程师沟通. 创建所需数据的json文件 json-server 此命令可以帮助我们快速创建一个 ...

  5. ABC347题解

    省流:输+赢 D 按位分析. 既然两个数异或后的结果是 \(C\),那就考虑 \(C\) 中为 \(1\) 的数中有几个是在 \(X\) 当中的. 假如 \(\text{a - popcnt(X) = ...

  6. docker-20.10.24搭建ferry工单系统

    安装文档 https://www.fdevops.com/docs/ferry-tutorial-document/introduction 必须要有docker环境,19.03以上的 本文档需用户自 ...

  7. 如果你也用过 struts2.简单介绍下 springMVC 和 struts2 的区别有哪些?

    a.springmvc 的入口是一个 servlet 即前端控制器,而 struts2 入口是一个 filter 过虑器. b.springmvc 是基于方法开发(一个 url 对应一个方法),请求参 ...

  8. vite+vue3+ts+elementPlus前端框架搭建 [一]

    记录下搭建vite + vue3 + ts + elementPlus项目的过程及遇到的问题. 建议使用pnpm安装依赖,npm切换到pnpm 链接地址:[https://www.pnpm.cn/in ...

  9. 基于SDF的光照效果

    基于SDF的光照效果 好久没写博客了,怠惰了,就当爬了一步 原神二次元风格面部渲染 效果 Show me the code Shader "Unlit/SDF" { Propert ...

  10. WPF/C#:如何实现拖拉元素

    前言 在Canvas中放置了一些元素,需要能够拖拉这些元素,在WPF Samples中的DragDropObjects项目中告诉了我们如何实现这种效果. 效果如下所示: 拖拉过程中的效果如下所示: 具 ...