当前位置:网站首页>npm --package.json---require
npm --package.json---require
2022-08-02 03:39:00 【cjx177187】
npm:
Instructions for the small black window:
i和install是一样的
npm i 模块名字x1 模块名字x2 模块名字x3 -g //把模块x1 x2 x3The three modules are downloaded to the global installation path
npm i 模块名字x1 模块名字x2 模块名字x3
或者
npm i 模块名字x1 模块名字x2 模块名字x3 --save //把模块x1 x2 x3The three modules are downloaded to the project installation path(inside the current project 的node_modules)
After downloading third-party modules npmThe downloaded third-party module name and version are written in the dependencies in the project configuration file
wait to learn laterwebpack就懂了
npm i x1 --save
npm i x1 --save-dev
npm i x1 -S
npm i x1 -D
npm i
这个指令 会去项目的配置文件中找到依赖的包 全部下载
npm run dev
这个指令会去项目的配置文件中找到scripts字段运行里面的dev指令
package.josn:
Configuration files belonging to the project 用于记录整个项目的一些信息===>项目名、作者信息
项目名==>项目的名字
"scripts":{"dev":"node index.js"} 启动指令 主要用于小黑窗的npm启动 npm run dev
"dependencies" 项目依赖
require:
node.js环境中的全局函数:require
引入前端的js文件用import
后端运行时引入第三方js文件 就用require()也可以用import(es6语法)
node.js中有3种模块
====>内置模块===>核心模块【node.js安装时就配置好的】
var fs=require("fs")
====>第三方模块 【下载后使用】npm I 模块名
var mime=require("mime")
====>自己定义的模块
var mytool=require("mytool")
举例:
利用require导入一个自己的模块mytool,然后调用mytool模块中的tool函数
注意:填写正确路径,后缀名最好的写上
代码:
var mytool=require("./mytool.js")
mytool.tool()
新建一个mytool.js在里面导入 我们想要调用的tool函数
代码:
module.exports={
tool(){
console.log(6666)
}
}
运行代码

require是导出,exports是导入
require(“fs”)会去哪里找文件?
去当前项目中的node_modules文件中 找fs文件夹中的package.json中main字段对应的路径然后引入;没有就去node的安装包中的全局安装包路径中找也是找package.json中main字段对应的路径然后引入;如果还是没找到,就会去核心库里卖弄去找,还是没找到就会报错
流程:
- 当前项目的node_modules文件夹
- 全局安装包中的node_global文件夹===>node_modules文件夹
- 全局安装包中的node_modules文件夹===>npm===>node_modules文件夹[核心库]
边栏推荐
- Source Insight 使用教程(2)——常用功能
- 区间问题 : 今年暑假不AC
- kettle 安装与配置
- 由中序遍历和前序遍历得到后序遍历(树的遍历)
- 【 application 】 life many years of operations, what turned scored 12 k + annual bonus salary?
- 新工程加载YOLOV6的预训练权重问题
- IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
- Customer Rating Control
- __dirname
- Phospholipid-polyethylene glycol-hydrazide, DSPE-PEG-Hydrazide, DSPE-PEG-HZ, MW: 5000
猜你喜欢

配置mmdet来训练Swin-Transformer之一配置环境

微信小程序云开发如何将页面生成为pdf?

subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.

AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'

微信小程序自定义swiper轮播图面板指示点|小圆点|进度条

Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000

URL module

微信小程序怎么批量生成带参数的小程序码?

DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group

require模块化语法
随机推荐
sh: 1: curl: not found
微信小程序九宫格抽奖和转盘抽奖的实现
我的小笔记 =》原生微信小程序
网址URL
STM32 CAN过滤器
np.isnan()
Deveco studio Hongmeng app access network detailed process (js)
页面加载流程
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
基本运算符
Advanced gradient of skeleton effect, suitable for waiting for pictures
The difference between the knowledge question and answer session with the knowledge
parser = argparse.ArgumentParser()解析
Cut out web icons through PS 2021
我的小笔记 =》其他东东
L1-039 古风排版(C)
小程序 van-cell 换行能左对齐问题
C语言入门小游戏—三子棋
Guangzhou Huawei Interview Summary
客户评分控件