工具软件 node yarn


原文链接: 工具软件 node yarn

比较详细的npm命令查看

registry = http://registry.npm.taobao.org/ #淘宝npm镜像

  1. 配置国内镜像
    yarn config set registry https://registry.npm.taobao.org
  2. 忽略node版本
    yarn config set ignore-engines true

  3. chromedriver : Saving to 安装卡住
    yarn config set "chromedriver_cdnurl" "https://npm.taobao.org/mirrors/chromedriver"
    yarn config set phantomjs_cdnurl https://npm.taobao.org/dist/phantomjs
    yarn config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver
    yarn config set operadriver_cdnurl http://npm.taobao.org/mirrors/operadriver
    yarn config set SASS_BINARY_SITE http://npm.taobao.org/mirrors/node-sass
    yarn config set SQLITE3_BINARY_SITE http://npm.taobao.org/mirrors/sqlite3
    yarn config set ELECTRON_MIRROR http://npm.taobao.org/mirrors/electron
    yarn config set PYTHON_MIRROR http://npm.taobao.org/mirrors/python

    2.6 国内抓取node-sass失败的解决方案

使用淘宝镜像

$ SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass

或者使用淘宝镜像cnpm

$ cnpm install node-sass

用yarn取代npm
Yarn is a package manager for your code.

  1. 安装(升级)yarn
    $ npm install -g yarn

  2. yarn常用命令
    npm init => $ yarn init
    npm install => $ yarn install
    $ yarn install --force #强制所有包重新下载
    npm install --save [package] => $ yarn add [package]
    npm install --save-dev [package] => $ yarn add [package] --dev
    npm install --global [package] => $ yarn global add [package]
    rm -rf node_modules && npm install => $ yarn upgrade [package]
    $ yarn upgrade [package] --ignore-engines #忽略引擎

    npm uninstall --save [package] =>
    npm uninstall --save-dev [package] => $ yarn remove [package]
    npm cache clean => $ yarn cache clean

    针对国内的设置

    $ yarn config set registry https://registry.npm.taobao.org

    使用XX-Net的可设置下http代理

    $ yarn config set proxy http://127.0.0.1:8087
    $ yarn config set https-proxy http://127.0.0.1:8087
    $ yarn config set strict-ssl false -g

    还原设置

    $ yarn config delete registry
    $ yarn config delete proxy
    $ yarn config delete https-proxy
    $ yarn config delete strict-ssl

    • yarn的 strict-ssl 配置目前存在BUG,需手动修改 .yarnrc 文件(located in \Users\ in Windows)【yarn/issues#980

    进入vi修改.yarnrc

    $ vi ~/.yarnrc

    .yarnrc内容:

      THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
      yarn lockfile v1
      strict-ssl false
    

    查看 npm 的版本

    $ npm -v

    为npm init设置默认值

    $ npm set init-author-name 'cycjimmy'
    $ npm set init-author-email 'cycjimmy@gmail.com'
    $ npm set init-author-url 'https://github.com/cycjimmy'
    $ npm set init-license 'MIT'

    初始化生成一个package.json文件。

    使用 -y 可以跳过提问阶段,直接生成package.json文件
    $ npm init -y

    列出当前项目安装的所有模块包

    $ npm ls --depth=0

    npm install默认会安装dependencies字段和devDependencies字段中的所有依赖包

    $ npm i

    针对国内可以加上参数

    $ npm --registry=https://registry.npm.taobao.org i

    安装依赖包

    –save:添加到dependencies,可简化为-S
    –save-dev: 添加到devDependencies,可简化为-D
    $ sudo npm i -g [package name]
    $ npm i [package name]
    $ npm i [package name] -S
    $ npm i [package name] -D

    更新依赖包

    -S表示保存新的依赖包版本号到package.json
    $ npm update -S

    递归更新

    npm update只更新顶层依赖包,而不更新依赖的依赖,如果想递归更新取,使用下面的命令
    $ npm --depth 9999 update

    卸载依赖包

    $ npm uninstall [package name]
    $ npm uninstall [package name] -global

    执行任务

    $ npm run [task name]

    国内镜像的设置

    $ npm config set registry=http://registry.npmjs.org

    使用代理 XX-Net的可设置下http代理

    $ npm config set proxy http://127.0.0.1:8087
    $ npm config set https-proxy http://127.0.0.1:8087
    $ npm config set strict-ssl false -g

    还原设置

    $ npm config delete registry
    $ npm config delete proxy
    $ npm config delete https-proxy
    $ npm config delete strict-ssl

    列出所有npm配置项目

    $ npm config ls -l

    • strict-ssl 需手动修改 .npmrc 文件(located in \Users\ in Windows)
      在 .npmrc 文件中添加
      strict-ssl=false




`