首先区要分脚手架版本:若安装了最新版本脚手架,想用老版本脚手架,创建vue2项目,需要拉取vue-cli2.x的模板才可以用!!
拉取模板命令: npm install @vue/cli-init -g
创建Vue2的初始化方式
vue init webpack vue-cli2test
1、项目名称:默认
? Project name vue-cli2test
2、项目描述:默认
? Project description A Vue.js project
3、作者信息:默认读取git信息
? Author baijunguo <guobj@jixingkeji.net>
4、模板渲染:runtime-only,性能高,代码量少,项目会轻6kb)
runtime-compiler:template > ast(抽象语法树) > render(函数) > 虚拟dom > 真实dom
runtime-only:render(函数) > 虚拟dom > 真实dom
? Vue build standalone
5、安装路由:y
? Install vue-router? Yes
6、代码格式校验:n
? Use ESLint to lint your code? No
7、单元测试:n
? Set up unit tests No
8、端到端测试:n
? Setup e2e tests with Nightwatch? No
9、安装方式:npm
? Should we run `npm install` for you after the project has been created? (recommended) npm
回车…巴拉巴拉开始初始化
看到Project initialization finished!项目初始化完成
创建Vue3的初始化方式(新版本脚手架创建Vue2也是同理)
输入创建Vue3项目命令
E:\>vue create vue-3admin
默认配置与手动选择功能
Vue CLI v4.5.13
? Please pick a preset: (Use arrow keys)
> Default ([Vue 2] babel, eslint) Vue2默认配置
Default (Vue 3) ([Vue 3] babel, eslint) Vue3默认配置
Manually select features 这里演示手动选择功能,不用后续安装路由,状态管理..
空格选中,安装功能
Vue CLI v4.5.13
? Check the features needed for your project:
>(*) Choose Vue version Vue版本选择
(*) Babel ES6转ES5
( ) TypeScript
( ) Progressive Web App (PWA) Support
(*) Router 路由
(*) Vuex 状态管理
(*) CSS Pre-processors CSS预处理器
( ) Linter / Formatter
( ) Unit Testing
( ) E2E Testing
版本选择:3.x
Vue CLI v4.5.13
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with
2.x
> 3.x
路由的history 模式:n
Vue CLI v4.5.13
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with 3.x
? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) n
Sass/SCSS (with node-sass)
Vue CLI v4.5.13
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with 3.x
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default):
Sass/SCSS (with dart-sass)
> Sass/SCSS (with node-sass)
Less
Stylus
In package.json
Vue CLI v4.5.13
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with 3.x
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Where do you prefer placing config for Babel, ESLint, etc.?
In dedicated config files
> In package.json
将此保存为将来项目的预设?:n
Vue CLI v4.5.13
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with 3.x
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Where do you prefer placing config for Babel, ESLint, etc.? In package.json
? Save this as a preset for future projects? (y/N) n
成功创建Vue项目,Successfully created project vue-3admin.
Vue CLI v4.5.13
✨ Creating project in E:\vue-3admin.
� Initializing git repository...
⚙️ Installing CLI plugins. This might take a while...
> core-js@3.18.2 postinstall E:\vue-3admin\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
> ejs@2.7.4 postinstall E:\vue-3admin\node_modules\ejs
> node ./postinstall.js
added 1220 packages from 636 contributors in 20.652s
81 packages are looking for funding
run `npm fund` for details
� Invoking generators...
� Installing additional dependencies...
> node-sass@4.14.1 install E:\vue-3admin\node_modules\node-sass
> node scripts/install.js
Cached binary found at C:\Users\疾风亦有归途\AppData\Roaming\npm-cache\node-sass\4.14.1\win32-x64-72_binding.node
> node-sass@4.14.1 postinstall E:\vue-3admin\node_modules\node-sass
> node scripts/build.js
Binary found at E:\vue-3admin\node_modules\node-sass\vendor\win32-x64-72\binding.node
Testing binary
Binary is fine
added 110 packages from 73 contributors in 7.418s
85 packages are looking for funding
run `npm fund` for details
⚓ Running completion hooks...
� Generating README.md...
� Successfully created project vue-3admin.
� Get started with the following commands:
$ cd vue-3admin
$ npm run serve
E:\>