Vue3学习笔记01:使用NPM方法安装Vue3

一、使用淘宝NPM镜像

(一)为何使用淘宝镜像

  • 国内直接使用npm官方镜像非常慢,推荐使用淘宝NPM镜像,它是一个完整npmjs.org镜像,可用此代替官方版本(只读),目前同步频率为10分钟1次,保证尽量与官方服务同步。

(二)安装淘宝NPM镜像

  • 安装淘宝定制的cnpm,代替替默认的npm
  • 执行命令:npm install -g cnpm --registry=https://registry.npmmirror.com
    在这里插入图片描述

(三)查看淘宝NPM镜像版本

  • 执行命令:cnpm -v,目前版本是7.1.1
    在这里插入图片描述

二、使用CNPM安装Vue最新稳定版

  • 在用 Vue.js 构建大型应用时推荐使用cnpm安装,能很好地和WebpackBrowserify模块打包器配合使用

(一)安装Vue最新稳定版

  • 执行命令:cnpm install vue@next
    在这里插入图片描述

(二)查看Vue命令行工具vue-cli版本

  • 执行命令:vue --version
    在这里插入图片描述
  • 对于Vue 3,至少应该使用npm上可用的Vue CLI v4.5作为@vue/cli
  • 如果vue cli版本不满足Vue3的条件,那么执行vue upgrade --next升级到最新稳定版
    在这里插入图片描述

(三)安装全局插件 - @vue/cli-init

  • 执行命令:cnpm i -g @vue/cli-init
    在这里插入图片描述

三、使用vue init创建Vue项目

(一)初始化Vue项目

  • 执行命令:vue init webpack vue3-demo
    在这里插入图片描述
C:\Users\Administrator>vue init webpack vue3-demo

? Project name vue3-demo
? Project description a Vue.js project
? Author howard2005
? Vue build (Use arrow keys)
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner jest
? Setup e2e tests with Nightwatch? Yes
? Should we run `npm install` for you after the project has been created? (recom
? Should we run `npm install` for you after the project has been created? (recom

mended) npm

   vue-cli · Generated "vue3-demo".


# Installing project dependencies ...
# ========================

npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser
. This package will no longer receive updates.
npm WARN deprecated [email protected]: This loader has been deprecated. Please
 use eslint-webpack-plugin
npm WARN deprecated [email protected]: Deprecated. Please use ht
tps://github.com/webpack-contrib/mini-css-extract-plugin
npm WARN deprecated [email protected]: out of support
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not
 recommended for usage due to the number of issues. Because of the V8 engine whi
ms, feature detection in old core-js versions could cause a slowdown up to 100x
even if nothing is polyfilled. Please, upgrade your dependencies to the actual v
ersion of core-js.
npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Br
owserslist >3.0 config used in other tools.
npm WARN deprecated [email protected]: request has been deprecated, see https://git
hub.com/request/request/issues/3142
npm WARN deprecated [email protected]: support for ECMAScript is superseded by `ug
lify-js` as of v3.13.0
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates
 since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: Switch to the `bfj` package for fixes and n
ew features!
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older v
ersions may use Math.random() in certain circumstances, which is known to be pro
blematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer suppor
ted. Please update to mkdirp 1.x. (Note that the API surface has changed to use
Promises in 1.x.)
npm WARN deprecated [email protected]: Please use the native JSON object instead of JS
ON 3
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and coul
d be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: flatten is deprecated in favor of utility fra
meworks such as lodash.
npm WARN deprecated [email protected]: CircularJSON is in maintenance only, fl
atted is its successor.
npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Bro
wserslist >3.0 config used in other tools.
npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrad
e to v2.x.x.
npm WARN deprecated [email protected]: some dependency vulnerabilities fixed, support f
or node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at leas
t 2.1.6 to avoid a serious bug with socket data flow and an import issue introdu
ced in 2.1.0
npm WARN deprecated [email protected]: The querystring API is considered Legacy.
 new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrad
e to v2.x.x.
npm WARN deprecated [email protected]: use String.prototype.padStart()
npm WARN deprecated [email protected]: request-promise-native has bee
n deprecated because it extends the now deprecated request package, see https://
github.com/request/request/issues/3142
npm WARN deprecated [email protected]: See https://github.com/lydell/sour
ce-map-resolve#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#dep
recated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprec
ated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-m
ap-url#deprecated

> [email protected] install C:\Users\Administrator\vue3-demo\node_modules\chro
medriver
> node install.js

Current existing ChromeDriver binary is unavailable, proceding with download and
 extraction.
Downloading from file:  https://chromedriver.storage.googleapis.com/2.46/chromed
river_win32.zip
Saving to file: C:\Users\Administrator\AppData\Local\Temp\2.46\chromedriver\chro
medriver_win32.zip
Received 781K...
Received 1568K...
Received 2352K...
Received 3136K...
Received 3920K...
Received 4523K total.
Extracting zip contents
Copying to target path C:\Users\Administrator\vue3-demo\node_modules\chromedrive
r\lib\chromedriver
Done. ChromeDriver binary available at C:\Users\Administrator\vue3-demo\node_mod
ules\chromedriver\lib\chromedriver\chromedriver.exe

> [email protected] postinstall C:\Users\Administrator\vue3-demo\node_modules\core-
js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfill
ing JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Colle
ctive or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a goo
d job -)


> [email protected] postinstall C:\Users\Administrator\vue3-demo\node_modules\es5-
ext
>  node -e "try{require('./_postinstall')}catch(e){}"


> [email protected] postinstall C:\Users\Administrator\vue3-demo\nod
e_modules\webpack\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js

npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.3 (node_modules\sa
ne\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.2.13: wanted {
    
    "os":"darwin","arch":"any"} (current: {
    
    "os":"win32","arch":"x64"
})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\ch
okidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.3.2: wanted {
    
    "os":"darwin","arch":"any"} (current: {
    
    "os":"win32","arch":"x64"}
)
npm WARN [email protected] requires a peer of ajv@^5.0.0 but none is installed.
 You must install peer dependencies yourself.

added 1836 packages from 1115 contributors in 104.944s


Running eslint --fix to comply with chosen preset rules...
# ========================


> [email protected] lint C:\Users\Administrator\vue3-demo
> eslint --ext .js,.vue src test/unit test/e2e/specs "--fix"


# Project initialization finished!
# ========================

To get started:

  cd vue3-demo
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

C:\Users\Administrator>

(二)运行Vue项目

  • 进入项目,执行命令:cnpm run dev
    在这里插入图片描述
    在这里插入图片描述

(三)浏览器查看应用运行结果

  • 访问http://localhost:8080
    在这里插入图片描述

四、使用Vite创建Vue项目

(一)Vite简介

  • Vite 是一个 web 开发构建工具,由于其原生 ES 模块导入方式,可以实现闪电般的冷服务器启动。
  • 使用 Vite 快速构建 Vue 项目的语法格式:npm init vite-app <project-name>

(二)利用Vite创建Vue项目

  • 执行命令:npm init vite-app vue3-demo2
    在这里插入图片描述

(三)运行Vue项目

  • 进入项目目录vue3-demo2,执行命令:npm install
    在这里插入图片描述
  • 执行命令:npm run dev
    在这里插入图片描述

(四)浏览器查看应用运行结果

  • 访问http://localhost:3000
    在这里插入图片描述
  • 访问http://192.168.214.112:3000/
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/howard2005/article/details/124208206