一.npm安装(全局安装、本地安装、链接依赖)
1.1全局安装指令:npm install -g packageName(模块名称 )
1.2本地安装指令:npm install react-native-aliyun-push(模块名称) --save //安装在package.json的dependencies中(生产环境依赖)
npm install react-native-aliyun-push(模块名称) --save -dev //安装package.json的devDepencies中(开发环境依赖)
1.3链接依赖环境指令:react-native link react-native-aliyun-push(模块名称)
二.npm删除
2.1若没有链接依赖环境时:npm uninstall react-native-aliyun-push
2.2若链接依赖环境时:需先接触依赖环境链接在删除依赖。
(1)react-native unlink react-native-aliyun-push(模块名称)
(2)npm uninstall react-native-aliyun-push(模块名称)
三.npm发布
3.1npm注册:npm adduser (注册完后到 https://www.npmjs.com/ 用注册时填写到邮箱激活一下不让是不能使用的)

3.2npm登陆:npm adduser

3.3npm init (初始化)
package name:可在初始化是填写、也是初始化完以后在`package.json`内填写


3.4在项目根目录创建 index.js 文件编写组件代码 (已react-native为例)
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
class index extends Component {
constructor(props){
super(props);
this.state={
};
}
componentDidMount(){
}
render() {
return (
<View style={styles.contain}>
<Text>我是自定义的组件</Text>
</View>
);
}
}
const styles = StyleSheet.create({
contain: {
height: 30,
width:'100%',
backgroundColor:'yellow'
}
});
export default index;
3.5 在项目根目录下 (1) npm login (2) npm publish
错误总结:
(1)此包名已经被注册

(2)邮箱未验证

(3)镜像问题

执行:npm config set registry=http://registry.npmjs.org
四.npm撤销(24小时内可以撤销)
npm unpublish baoming --force

觉得有用的小伙伴点个关注和小红心就行😄,么么哒。
网友评论