yarn常见指令,yarn和npm

本文章不着重介绍yarn,而是罗列项目常用的指令,方便在项目快速使用,更多原理另行百度可查

创建一个新项目

yarn init

接着提示一下

name (your-project):
version (1.0.0):
description:
entry point (index.js):
git repository:
author:
license (MIT):

生成package.json文件

{
  "name": "my-new-project",
  "version": "1.0.0",
  "description": "My New Project description.",
  "main": "index.js",
  "repository": {
    "url": "https://example.com/your-username/my-new-project",
    "type": "git"
  },
  "author": "Your Name ",
  "license": "MIT"
}

添加、更新、删除依赖

yarn / yarn install 一键安装jpackage.json所有包
yarn add [package] — 添加包,会自动安装最新版本,注意会覆盖指定版本号!!!
yarn add [package]@[version] — 带版本号安装
yarn remove [package] 移除某个包
yarn upgrade [package] 更新一个包
yarn add vue 安装一个包
yarn add [email protected]  安装一个包
yarn upgrade vue 更新一个包
yarn upgrade [email protected] 指定更新某个版本的包
yarn remove vue 

yarn add vue 安装到dependencies
yarn add vue --save-dev 安装到devDependencies

npm 和yarn比较

npm yarn 用法
npm install yarn install 一键安装package.json的所有包
npm install [package] --save / -S yarn add [package] 安装到dependencies
npm install [package] --save-dev/ -D yarn add [package] --save-dev 安装到devDependencies
npm i [package]@[版本号] yarn add [package]@[版本号] 指定版本号下载更新
npm install [package] --global yarn global add [package] 全局安装某个包
npm update --global yarn updade upgrade 更新所有包
npm uninstall [package] yarn remove [package] 删除某个包
yarn常见指令,yarn和npm_第1张图片
aonaotu-download.png

你可能感兴趣的:(yarn常见指令,yarn和npm)