- 全局安装
create-react-native-module
模块
$ yarn global add create-react-native-module
- 创建插件工程
创建工程时需要指定package-identifier
, 按项目实际命名要求处理,未指定默认为com.reactlibrary
$ create-react-native-module --package-identifier com.example.myplugin --generate-example my-plugin
生成的插件项目名称为 react-native-my-plugin
, android 项目的 packageName
为 com.example.myplugin
,项目中包含 example
目录,目录中包含插件使用的样例代码。
- 安装相关依赖
$ yarn install
注:直接执行 create-react-native-module
,可查看命令支持相关参数说明:
Usage: create-react-native-module [options] <name>
creates a React Native library module for one or more platforms
Options:
-V, --version output the version number
--module-name [moduleName] The module package name to be used in package.json. Default: react-native-(name in param-case)
--view Generate the package as a very simple native view component
--object-class-name [objectClassName] The name of the object class to be exported by both JavaScript and native code. Default: (name in PascalCase)
--prefix [prefix] DEPRECATED: The prefix of the name of the object class to be exported by both JavaScript and native code, ignored if --object-class-name is specified (default: "")
--module-prefix [modulePrefix] The prefix of the generated module package name, ignored if --module-name is specified (default: "react-native")
--package-identifier [packageIdentifier] [Android] The Java package identifier used by the Android module (default: "com.reactlibrary")
--platforms <platforms> Platforms the library module will be created for - comma separated (default: "ios,android")
--tvos-enabled Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)
--github-account [githubAccount] The github account where the library module is hosted (default: "github_account")
--author-name [authorName] The author's name (default: "Your Name")
--author-email [authorEmail] The author's email (default: "yourname@email.com")
--license [license] The license type (default: "MIT")
--use-apple-networking [iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code
--generate-example Generate an example project and add the library module to it with symlink by defult, with overwrite of example metro.config.js to add workaround for Metro symlink issue - requires both react-native-cli and yarn to be installed globally
--example-file-linkage DEPRECATED: do `yarn add file:../` instead of `yarn add link:../` in a generated example project, and add a postinstall workaround script, with no overwrite of example metro.config.js
--example-name [exampleName] Name for the example project (default: "example")
--example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: "react-native@latest")
--write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile
-h, --help display help for command
网友评论