zoukankan      html  css  js  c++  java
  • npm

    npm(Node package manager) 使用介绍

    解决包之间的依赖关系

    • 需安装node.js

      • 下载后安装即可

      • npm -v
        node -v
    • 更新npm

      • npm install npm@5.4.0 -g
        npm install npm@latest -g
        # -g 表示全局环境,只有这样,npm才可以在任何目录识别
    • 修改镜像地址:

      • npm config set registry https://registry.npm.taobao.org
      • # 安装cnmp以后使用cnmp就是使用国内进行,推荐
        npm install -g cnpm --registry=https://registry.npm.taobao.org
      •  npm install --registry=https://registry.npm.taobao.org

    Package.json

    新建文件夹,建立package.json文件

    {
       "name": "xxx",  # 名称不能大写,不能有注释
       "version": "1.0",
       "main":"index.js", # 设置入口文件
       "scripts":{# 自定义命令
       
    }
    "author":"",
    "license":"ISC",
       "dependencies":{  # 依赖文件
    }
    }

    npm常用操作

    image-20200525120425126image-20200525120549200image-20200525120812047

    cd 20.2  # 进入文件夹
    npm init -y # 初始化文件---》会生成package.json y表示默认参数
    npm i jquery --save
    # 安装jquery -----》产生node_modules目录专门存放模块,
    # 与package-lock.json,
    # npm i bootstrap,vue
    # 包名不能乱写,查询地址:https://www.npmjs.com/
    # save 表示依赖写入package.json  
    #   --save-dev 表示只有生产环境使用
    nmp -g ---> cnmp -g
    npm --save ---> cnmp -S
    npm --save-dev ---> cnpm -D
    # html 标签src引入即可使用
    # 此时删除node_modules,也可以
    # 在另一个环境中,即可还原所有node_modules
    npm i
    # 当不需要时卸载即可
    npm uninstall xxx
    # 更新
    npm update jquery
    # 指定版本
    npm install jquery@3.0.0

    使用别人的包

    # 自己的包入口文件index.js
    node index.js # 运行

    # index.js 中使用其他包
    # 会到所有的node_modules寻找名字为math的软件包,根据package.json 入口文件引入
    let math = require('math')
    let res = math.sum([1,2,3])
    console.log(res)

     

  • 相关阅读:
    小程序 短信验证码 倒计时 变量作用域
    File syncing and sharing software with file encryption and group sharing, emphasis on reliability and high performance.
    图片合并与截断
    宽度分离
    无宽度准则
    linux系统/var/log目录下的信息详解
    Connection Phase Packets
    select version();desc mysql.user;
    mysql user password plugin
    Please read "Security" section of the manual to find out how to run mysqld as root!
  • 原文地址:https://www.cnblogs.com/Dean0731/p/12956891.html
Copyright © 2011-2022 走看看