diff --git a/404.html b/404.html index d21429400..ed083d405 100644 --- a/404.html +++ b/404.html @@ -1 +1 @@ -404: This page could not be found

404

This page could not be found.

\ No newline at end of file +404: This page could not be found

404

This page could not be found.

\ No newline at end of file diff --git a/_next/static/Q84JHp9lMvSuLGVBevcfY/_buildManifest.js b/_next/static/U1WNKv__K7ARkuXXuV7pB/_buildManifest.js similarity index 89% rename from _next/static/Q84JHp9lMvSuLGVBevcfY/_buildManifest.js rename to _next/static/U1WNKv__K7ARkuXXuV7pB/_buildManifest.js index 3c5896296..eae99806a 100644 --- a/_next/static/Q84JHp9lMvSuLGVBevcfY/_buildManifest.js +++ b/_next/static/U1WNKv__K7ARkuXXuV7pB/_buildManifest.js @@ -1 +1 @@ -self.__BUILD_MANIFEST=function(e,s){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":[e,s,"static/chunks/pages/index-5981cefc764efe90.js"],"/_error":["static/chunks/pages/_error-c26e849581894657.js"],"/build":[e,s,"static/chunks/pages/build-9b149cd009539b7e.js"],"/create":[e,s,"static/chunks/pages/create-e3c0335e505fe47e.js"],"/faq":[e,s,"static/chunks/pages/faq-53749b95b1244585.js"],sortedPages:["/","/_app","/_error","/build","/create","/faq"]}}("static/css/445c4173ffc2bf04.css","static/chunks/571-1ed7697133334290.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB(); \ No newline at end of file +self.__BUILD_MANIFEST=function(e,s){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":[e,s,"static/chunks/pages/index-5981cefc764efe90.js"],"/_error":["static/chunks/pages/_error-c26e849581894657.js"],"/build":[e,s,"static/chunks/pages/build-9b149cd009539b7e.js"],"/create":[e,s,"static/chunks/pages/create-3327154f5dabf16e.js"],"/faq":[e,s,"static/chunks/pages/faq-53749b95b1244585.js"],sortedPages:["/","/_app","/_error","/build","/create","/faq"]}}("static/css/445c4173ffc2bf04.css","static/chunks/571-1ed7697133334290.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB(); \ No newline at end of file diff --git a/_next/static/Q84JHp9lMvSuLGVBevcfY/_ssgManifest.js b/_next/static/U1WNKv__K7ARkuXXuV7pB/_ssgManifest.js similarity index 100% rename from _next/static/Q84JHp9lMvSuLGVBevcfY/_ssgManifest.js rename to _next/static/U1WNKv__K7ARkuXXuV7pB/_ssgManifest.js diff --git a/_next/static/chunks/nextra-data-en-US.json b/_next/static/chunks/nextra-data-en-US.json index 51c9c4938..9214871fc 100644 --- a/_next/static/chunks/nextra-data-en-US.json +++ b/_next/static/chunks/nextra-data-en-US.json @@ -1 +1 @@ -{"/build":{"title":"Build a React Native library","data":{"":"When code is in non-standard syntaxes such as JSX, TypeScript etc, it needs to be compiled before it can run. Configuring this manually can be error-prone and annoying. react-native-builder-bob aims to simplify this process by wrapping babel and tsc and taking care of the configuration. See this section for a longer explanation.Supported targets are:\nGeneric CommonJS build\nES modules build for bundlers such as webpack\nTypeScript definitions\nFlow definitions (copies .js files to .flow files)\nIf you created a project with create-react-native-library, react-native-builder-bob is already pre-configured to build your project. You don't need to configure it again.The following configuration steps are for projects not created with create-react-native-library.","automatic-configuration#Automatic configuration":"To automatically configure your project to use react-native-builder-bob, open a Terminal and run:\nnpx react-native-builder-bob@latest init\nThis will ask you a few questions and add the required configuration and scripts for building the code. The code will be compiled automatically when the package is published.You can find details on what exactly it adds in the Manual configuration section.","manual-configuration#Manual configuration":"To configure your project manually, follow these steps:\nFirst, install react-native-builder-bob in your project. Open a Terminal in your project, and run:\nyarn add --dev react-native-builder-bob\nIn your package.json, specify the targets to build for:\n\"react-native-builder-bob\": {\n \"source\": \"src\",\n \"output\": \"lib\",\n \"targets\": [\n \"commonjs\",\n \"module\",\n \"typescript\",\n ]\n}\nSee the Options section for more details.\nAdd bob to your prepare or prepack step:\n\"scripts\": {\n \"prepare\": \"bob build\"\n}\nNote that there is a difference between prepare and prepack scripts:\nprepare is run when the package is published, as well as when its is installed from a git URL. It may also run when dependencies are installed based on the package manager.\nprepack only runs when the package is packed for publishing.\nIf you are not sure which one to use, we recommend going with prepare.\nConfigure the appropriate entry points:\n\"main\": \"lib/commonjs/index.js\",\n\"module\": \"lib/module/index.js\",\n\"react-native\": \"src/index.ts\",\n\"types\": \"lib/typescript/src/index.d.ts\",\n\"source\": \"src/index.ts\",\n\"files\": [\n \"lib\",\n \"src\"\n]\nHere is what each of these fields mean:\nmain: The entry point for the commonjs build. This is used by Node - such as tests, SSR etc.\nmodule: The entry point for the ES module build. This is used by bundlers such as webpack.\nreact-native: The entry point for the React Native apps. This is used by Metro. It's common to point to the source code here as it can make debugging easier.\ntypes: The entry point for the TypeScript definitions. This is used by TypeScript to type check the code using your library.\nsource: The path to the source code. It is used by react-native-builder-bob to detect the correct output files and provide better error messages.\nfiles: The files to include in the package when publishing with npm.\nMake sure to change specify correct files according to the targets you have enabled.NOTE: If you're building TypeScript definition files, also make sure that the types field points to a correct path. Depending on the project configuration, the path can be different for you than the example snippet (e.g. lib/typescript/index.d.ts if you have only the src directory and rootDir is not set).\nAdd the output directory to .gitignore and .eslintignore\n# generated files by bob\nlib/\nThis makes sure that you don't accidentally commit the generated files to git or get lint errors for them.\nAdd the output directory to jest.modulePathIgnorePatterns if you use Jest\n\"modulePathIgnorePatterns\": [\"/lib/\"]\nThis makes sure that Jest doesn't try to run the tests in the generated files.\nAnd we're done 🎉","options#Options":"The options can be specified in the package.json file under the react-native-builder-bob property, or in a bob.config.js file in your project directory.","source#source":"The name of the folder with the source code which should be compiled. The folder should include an index file.","output#output":"The name of the folder where the compiled files should be output to. It will contain separate folder for each target.","exclude#exclude":"Glob pattern to be used while filtering the unnecessary files. Defaults to '**/{__tests__,__fixtures__,__mocks__}/**' if not specified.Example:\n{\n \"exclude\": \"ignore_me/**\"\n}\nThis option only works with commonjs and module targets. To exclude files while building typescript, please see the tsconfig exclude field.","targets#targets":"Various targets to build for. The available targets are:","commonjs#commonjs":"Enable compiling source files with Babel and use commonjs module system.This is useful for running the code in Node (SSR, tests etc.). The output file should be referenced in the main field of package.json.By default, the code is compiled to support last 2 versions of modern browsers. It also strips TypeScript and Flow annotations, and compiles JSX. You can customize the environments to compile for by using a browserslist config.In addition, the following options are supported:\nconfigFile & babelrc (boolean): To customize the babel config used, you can pass the configFile option as true if you have a babel.config.js or babelrc option if you have a .babelrc. This may break the default configuration, so use these options only if you know what you're doing.\ncopyFlow (boolean): If your source code is written in Flow, You can specify the copyFlow option to copy the source files as .js.flow to the output folder. If the main entry in package.json points to the index file in the output folder, the flow type checker will pick these files up to use for type definitions.\nsourceMaps (boolean): Sourcemaps are generated by default alongside the compiled files. You can disable them by setting the sourceMaps option to false.\nExample:\n[\"commonjs\", { \"configFile\": true, \"copyFlow\": true }]","module#module":"Enable compiling source files with Babel and use ES module system. This is essentially same as the commonjs target and accepts the same options, but leaves the import/export statements in your code.This is useful for bundlers which understand ES modules and can tree-shake. The output file should be referenced in the module field of package.json.Example:\n[\"module\", { \"configFile\": true }]","typescript#typescript":"Enable generating type definitions with tsc if your source code is written in TypeScript.The following options are supported:\nproject (string): By default, the tsconfig.json file in the root of your project is used to generate the type definitions. You can specify a path to a different config by using the project option. This can be useful if you need to use different configs for development and production.\ntsc (string): The path to the tsc binary is automatically detected and defaults to the one installed in your project. You can use the tsc option to specify a different path.\nExample:\n[\"typescript\", { \"project\": \"tsconfig.build.json\" }]","commands#Commands":"The bob CLI exposes the following commands:","init#init":"This configures an existing project to use bob by adding the required configuration and dependencies. This is usually run with npx:\nnpx react-native-builder-bob@latest init","build#build":"This builds the project according to the configuration. This is usually run as part of the package's publishing flow, i.e. in the prepare or prepack scripts.\n\"scripts\": {\n \"prepare\": \"bob build\"\n}"}},"/create":{"title":"Scaffold a React Native library","data":{"":"If you want to create your own React Native library, scaffolding the project can be a daunting task. create-react-native-library can scaffold a new project for you with all the necessary tools configured.","features#Features":"Minimal boilerplate for libraries on which you can build upon\nExample React Native app to test your library code\nTypeScript to ensure type-safe code and better DX\nSupport for Turbo Modules & Fabric\nSupport for Kotlin on Android & Swift on iOS\nSupport for C++ to write cross-platform native code\nExpo for libraries without native code and web support\nESLint, Prettier, TypeScript, Lefthook and Release It pre-configured\nreact-native-builder-bob pre-configured to compile your files\nGitHub Actions pre-configured to run tests and lint on the CI","usage#Usage":"To create new project, run the following:\nnpx create-react-native-library@latest awesome-library\nThis will ask you a few questions about your project and generate a new project in a folder named awesome-library.After the project is created, you can find the development workflow in the generated CONTRIBUTING.md file.","local-library#Local library":"While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app. The local library is created outside of the android and ios folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in React Native docs.If you run create-react-native-library in an existing project containing a package.json, it'll be automatically detected and you'll be asked if you want to create a local library. You can also pass the --local flag to the command to explicitly create a local library:\nnpx create-react-native-library@latest awesome-library --local\nThe advantages of this approach are:\nIt's easier to upgrade React Native as you don't need to worry about custom code in android and ios folders.\nIt can be used with Expo managed projects with custom development client.\nIt's easier to copy the library to other projects or publish later if needed.\nThe boilerplate for the library doesn't need to be written from scratch.\nIt can be used with monorepos where the additional tooling in the default templates may not be needed.\nBy default, the generated library is automatically linked to the project using link: protocol when using Yarn and file: when using npm:\n\"dependencies\": {\n \"react-native-awesome-library\": \"link:./modules/awesome-library\"\n}\nThis creates a symlink to the library under node_modules which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup."}},"/faq":{"title":"Frequently Asked Questions","data":{"why-should-i-compile-my-project-with-react-native-builder-bob#Why should I compile my project with react-native-builder-bob?":"We often write our library code in non-standard syntaxes such as JSX, TypeScript etc. as well as proposed syntaxes which aren't part of the standard yet. This means that our code needs to be compiled to be able to run on JavaScript engines.When using the library in a React Native app, Metro handles compiling the source code. However, it's also possible to use them in other targets such as:\nBrowsers or bundlers such as webpack (if we support Web)\nNode.js for tests or SSR etc.\nSo the code needs to be precompiled so these tools can parse it. In addition, we need to generate type definition files for TypeScript etc.To handle such multiple targets, one solution could is to have multiple babel configs (or TypeScript configs) and have a babel-cli command in our package.json for compilation. Ideally, we should also keep the configs in sync between our several projects.As an example, this is a command that we had in one of the packages:\nbabel --extensions '.js,.ts,.tsx' --no-babelrc --config-file=./babel.config.publish.js src --ignore '**/__tests__/**' --copy-files --source-maps --delete-dir-on-start --out-dir dist && del-cli 'dist/**/__tests__' && yarn tsc --emitDeclarationOnly\nAs you can see, it's quite long and hard to read. There's even a separate babel.config.publish.js file. And this only works for webpack and Metro, and will fail on Node due to ESM usage.react-native-builder-bob wraps tools such as babel and typescript to simplify these common tasks across multiple projects. While it can be used for any library, it's primarily tailored to React Native projects to minimize the configuration required.","how-do-i-add-a-react-native-library-containing-native-code-as-a-dependency-in-my-library#How do I add a react-native library containing native code as a dependency in my library?":"If your library depends on another react-native library containing native code, you should do the following:\nAdd the native library to peerDependenciesThis means that the consumer of the library will need to install the native library and add it to the dependencies section of their package.json. It makes sure that:\nThere are no version conflicts if another package also happens to use the same library, or if the user wants to use the library in their app. While there can be multiple versions of a JavaScript-only library, there can only be one version of a native library - so avoiding version conflicts is important.\nThe package manager installs it in correct location so that autolinking can work properly.\nDon't add the native library to dependencies of your library, otherwise it may cause issues for the user even if it seems to work.\nAdd the native library to devDependenciesThis makes sure that you can use it for tests, and there are no other errors such as type errors due to the missing module.\nAdd the native library to dependencies in the package.json under exampleThis is equivalent to the consumer of the library installing the dependency, and is needed so that this module is also available to the example app.","how-to-upgrade-the-react-native-version-in-the-generated-project#How to upgrade the react-native version in the generated project?":"Since this is a library, the react-native version specified in the package.json is not relevant for the consumers. It's only used for developing and testing the library. If you'd like to upgrade the react-native version to test with it, you'd need to:\nBump versions of the following packages under devDependencies in the package.json:\nreact-native\nreact\n@types/react\n@types/react-native\nIf you have any other related packages such as react-test-renderer, make sure to bump them as well.\nUpgrade react-native in the example appThe example app is a React Native app that can be updated following the same process as a regular React Native app. The process will vary depending on if it's using Expo or React Native CLI. See the official upgrade guide for more details.\nTo avoid issues, make sure that the versions of react and react-native are the same in example/package.json and the package.json at the root.","how-does-the-library-get-linked-to-the-example-app-in-the-generated-project#How does the library get linked to the example app in the generated project?":"If you generate a project with create-react-native-library, you get an example app to test your library. It's good to understand how the library gets linked to the example app in case you want to tweak how it works or if you run into issues.There are 2 parts to this process.\nAliasing the JavaScript codeThe JavaScript (or TypeScript) source code is aliased to be used by the example app. This makes it so that when you import from 'your-library-name', it imports the source code directly and avoids having to rebuild the library for JavaScript only changes. We configure several tools to make this work:\nBabel is configured to use the alias in example/babel.config.js using babel-plugin-module-resolver. This transforms the imports to point to the source code instead.\nMetro is configured to allow importing from outside of the example directory by configuring watchFolders, and to use the appropriate peer dependencies. This configuration exists in the example/metro.config.js file.\nWebpack is configured to compile the library source code when running on the Web. This configuration exists in the example/webpack.config.js file.\nTypeScript is configured to use the source code for type checking by using the paths property under compilerOptions. This configuration exists in the tsconfig.json file at the root.\nLinking the native codeBy default, React Native CLI only links the modules installed under node_module of the app. To be able to link the android and ios folders from the project root, the path is specified in the example/react-native.config.js file.","how-to-test-the-library-in-an-app-locally#How to test the library in an app locally?":"You may have come across the yarn link and npm link commands, or used npm install ../path/to/folder or yarn add ../path/to/folder to test libraries locally. These commands may work for simple packages without build process, but they have different behavior from how a published package works, e.g. .npmignore is not respected, the structure of node_modules is different, etc. So we don't recommended using these approaches to test libraries locally.For more accurate testing, there are various other approaches:\nLocal tarball with npmFirst, temporarily change the version in package.json to something like 0.0.0-local.0. This version number needs to be updated to something different every time you do this to avoid stale content.Run the following command inside your library's root:\nnpm pack\nThis will generate a file like your-library-name-0.0.0-local.0.tgz in the root of the project.Then, you can install the tarball in your app:\nyarn add ../path/to/your-library-name-0.0.0-local.0.tgz\nOr if you use npm:\nnpm install ../path/to/your-library-name-0.0.0-local.0.tgz\nYalcYalc acts as a local repository for packages that can be used to test packages locally. It's similar to the previous workflow, but more convenient to use.You can find installation and usage instructions in the Yalc documentation.\nVerdaccioVerdaccio is a lightweight private npm registry that can be used to test packages locally. The advantage of using Verdaccio is that it allows to test the complete workflow of publishing and installing a package without actually publishing it to a remote registry.You can find installation and usage instructions in the Verdaccio documentation.","users-get-a-warning-when-they-install-my-library#Users get a warning when they install my library":"If users are using Yarn 1, they may get a warning when installing your library:\nwarning Workspaces can only be enabled in private projects.\nThis is because the example app is configured as a Yarn workspace, and there is a bug in Yarn 1 which causes this warning to be shown for third-party packages. It has no impact for the consumers of the library and the warning can be ignored. If consumers would like to get rid of the warning, there are 2 options:\nDisable workspacesIf the consumer doesn't use Yarn workspaces, they can disable it by adding the following to the .yarnrc file in the root of their project:\nworkspaces-experimental false\nUpgrade to Yarn 3Yarn 1 is no longer maintained, so it's recommended to upgrade to Yarn 3. Yarn 3 works with React Native projects with the node-modules linker. To upgrade, consumers can follow the official upgrade guide.It's also necessary to use node-modules linker. To use it, consumers can add the following to the .yarnrc.yml file in the root of their project:\nnodeLinker: node-modules"}},"/":{"title":"Introduction","data":{"":"This project is a collection of tools to make it easier to build React Native libraries. It contains the following CLIs:\ncreate-react-native-library - a CLI to scaffold a React Native library.\nreact-native-builder-bob - a CLI to build React Native libraries for various targets."}}} \ No newline at end of file +{"/build":{"title":"Build a React Native library","data":{"":"When code is in non-standard syntaxes such as JSX, TypeScript etc, it needs to be compiled before it can run. Configuring this manually can be error-prone and annoying. react-native-builder-bob aims to simplify this process by wrapping babel and tsc and taking care of the configuration. See this section for a longer explanation.Supported targets are:\nGeneric CommonJS build\nES modules build for bundlers such as webpack\nTypeScript definitions\nFlow definitions (copies .js files to .flow files)\nIf you created a project with create-react-native-library, react-native-builder-bob is already pre-configured to build your project. You don't need to configure it again.The following configuration steps are for projects not created with create-react-native-library.","automatic-configuration#Automatic configuration":"To automatically configure your project to use react-native-builder-bob, open a Terminal and run:\nnpx react-native-builder-bob@latest init\nThis will ask you a few questions and add the required configuration and scripts for building the code. The code will be compiled automatically when the package is published.You can find details on what exactly it adds in the Manual configuration section.","manual-configuration#Manual configuration":"To configure your project manually, follow these steps:\nFirst, install react-native-builder-bob in your project. Open a Terminal in your project, and run:\nyarn add --dev react-native-builder-bob\nIn your package.json, specify the targets to build for:\n\"react-native-builder-bob\": {\n \"source\": \"src\",\n \"output\": \"lib\",\n \"targets\": [\n \"commonjs\",\n \"module\",\n \"typescript\",\n ]\n}\nSee the Options section for more details.\nAdd bob to your prepare or prepack step:\n\"scripts\": {\n \"prepare\": \"bob build\"\n}\nNote that there is a difference between prepare and prepack scripts:\nprepare is run when the package is published, as well as when its is installed from a git URL. It may also run when dependencies are installed based on the package manager.\nprepack only runs when the package is packed for publishing.\nIf you are not sure which one to use, we recommend going with prepare.\nConfigure the appropriate entry points:\n\"main\": \"lib/commonjs/index.js\",\n\"module\": \"lib/module/index.js\",\n\"react-native\": \"src/index.ts\",\n\"types\": \"lib/typescript/src/index.d.ts\",\n\"source\": \"src/index.ts\",\n\"files\": [\n \"lib\",\n \"src\"\n]\nHere is what each of these fields mean:\nmain: The entry point for the commonjs build. This is used by Node - such as tests, SSR etc.\nmodule: The entry point for the ES module build. This is used by bundlers such as webpack.\nreact-native: The entry point for the React Native apps. This is used by Metro. It's common to point to the source code here as it can make debugging easier.\ntypes: The entry point for the TypeScript definitions. This is used by TypeScript to type check the code using your library.\nsource: The path to the source code. It is used by react-native-builder-bob to detect the correct output files and provide better error messages.\nfiles: The files to include in the package when publishing with npm.\nMake sure to change specify correct files according to the targets you have enabled.NOTE: If you're building TypeScript definition files, also make sure that the types field points to a correct path. Depending on the project configuration, the path can be different for you than the example snippet (e.g. lib/typescript/index.d.ts if you have only the src directory and rootDir is not set).\nAdd the output directory to .gitignore and .eslintignore\n# generated files by bob\nlib/\nThis makes sure that you don't accidentally commit the generated files to git or get lint errors for them.\nAdd the output directory to jest.modulePathIgnorePatterns if you use Jest\n\"modulePathIgnorePatterns\": [\"/lib/\"]\nThis makes sure that Jest doesn't try to run the tests in the generated files.\nAnd we're done 🎉","options#Options":"The options can be specified in the package.json file under the react-native-builder-bob property, or in a bob.config.js file in your project directory.","source#source":"The name of the folder with the source code which should be compiled. The folder should include an index file.","output#output":"The name of the folder where the compiled files should be output to. It will contain separate folder for each target.","exclude#exclude":"Glob pattern to be used while filtering the unnecessary files. Defaults to '**/{__tests__,__fixtures__,__mocks__}/**' if not specified.Example:\n{\n \"exclude\": \"ignore_me/**\"\n}\nThis option only works with commonjs and module targets. To exclude files while building typescript, please see the tsconfig exclude field.","targets#targets":"Various targets to build for. The available targets are:","commonjs#commonjs":"Enable compiling source files with Babel and use commonjs module system.This is useful for running the code in Node (SSR, tests etc.). The output file should be referenced in the main field of package.json.By default, the code is compiled to support last 2 versions of modern browsers. It also strips TypeScript and Flow annotations, and compiles JSX. You can customize the environments to compile for by using a browserslist config.In addition, the following options are supported:\nconfigFile & babelrc (boolean): To customize the babel config used, you can pass the configFile option as true if you have a babel.config.js or babelrc option if you have a .babelrc. This may break the default configuration, so use these options only if you know what you're doing.\ncopyFlow (boolean): If your source code is written in Flow, You can specify the copyFlow option to copy the source files as .js.flow to the output folder. If the main entry in package.json points to the index file in the output folder, the flow type checker will pick these files up to use for type definitions.\nsourceMaps (boolean): Sourcemaps are generated by default alongside the compiled files. You can disable them by setting the sourceMaps option to false.\nExample:\n[\"commonjs\", { \"configFile\": true, \"copyFlow\": true }]","module#module":"Enable compiling source files with Babel and use ES module system. This is essentially same as the commonjs target and accepts the same options, but leaves the import/export statements in your code.This is useful for bundlers which understand ES modules and can tree-shake. The output file should be referenced in the module field of package.json.Example:\n[\"module\", { \"configFile\": true }]","typescript#typescript":"Enable generating type definitions with tsc if your source code is written in TypeScript.The following options are supported:\nproject (string): By default, the tsconfig.json file in the root of your project is used to generate the type definitions. You can specify a path to a different config by using the project option. This can be useful if you need to use different configs for development and production.\ntsc (string): The path to the tsc binary is automatically detected and defaults to the one installed in your project. You can use the tsc option to specify a different path.\nExample:\n[\"typescript\", { \"project\": \"tsconfig.build.json\" }]","commands#Commands":"The bob CLI exposes the following commands:","init#init":"This configures an existing project to use bob by adding the required configuration and dependencies. This is usually run with npx:\nnpx react-native-builder-bob@latest init","build#build":"This builds the project according to the configuration. This is usually run as part of the package's publishing flow, i.e. in the prepare or prepack scripts.\n\"scripts\": {\n \"prepare\": \"bob build\"\n}"}},"/create":{"title":"Scaffold a React Native library","data":{"":"If you want to create your own React Native library, scaffolding the project can be a daunting task. create-react-native-library can scaffold a new project for you with all the necessary tools configured.","features#Features":"Minimal boilerplate for libraries on which you can build upon\nExample React Native app to test your library code\nTypeScript to ensure type-safe code and better DX\nSupport for Turbo Modules & Fabric\nSupport for Kotlin on Android & Swift on iOS\nSupport for C++ to write cross-platform native code\nExpo for libraries without native code and web support\nESLint, Prettier, TypeScript, Lefthook and Release It pre-configured\nreact-native-builder-bob pre-configured to compile your files\nGitHub Actions pre-configured to run tests and lint on the CI","usage#Usage":"To create new project, run the following:\nnpx create-react-native-library@latest awesome-library\nThis will ask you a few questions about your project and generate a new project in a folder named awesome-library.After the project is created, you can find the development workflow in the generated CONTRIBUTING.md file.","local-library#Local library":"While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app.If you run create-react-native-library in an existing project containing a package.json, it'll be automatically detected and you'll be asked if you want to create a local library. You can also pass the --local flag to the command to explicitly create a local library:\nnpx create-react-native-library@latest awesome-library --local\nThe local library is created outside of the android and ios folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in React Native docs.The advantages of this approach are:\nIt's easier to upgrade React Native as you don't need to worry about custom code in android and ios folders.\nIt can be used with Expo managed projects with custom development client.\nIt's easier to copy the library to other projects or publish later if needed.\nThe boilerplate for the library doesn't need to be written from scratch.\nIt can be used with monorepos where the additional tooling in the default templates may not be needed.\nBy default, the generated library is automatically linked to the project using link: protocol when using Yarn and file: when using npm:\n\"dependencies\": {\n \"react-native-awesome-library\": \"link:./modules/awesome-library\"\n}\nThis creates a symlink to the library under node_modules which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup.","writing-native-code#Writing native code":"Once the project is created, you can follow the official React Native docs to learn the API for writing native modules and components:\nNative Modules\nNative UI Components for Android\nNative UI Components for iOS\nTurbo Modules\nFabric Components"}},"/faq":{"title":"Frequently Asked Questions","data":{"why-should-i-compile-my-project-with-react-native-builder-bob#Why should I compile my project with react-native-builder-bob?":"We often write our library code in non-standard syntaxes such as JSX, TypeScript etc. as well as proposed syntaxes which aren't part of the standard yet. This means that our code needs to be compiled to be able to run on JavaScript engines.When using the library in a React Native app, Metro handles compiling the source code. However, it's also possible to use them in other targets such as:\nBrowsers or bundlers such as webpack (if we support Web)\nNode.js for tests or SSR etc.\nSo the code needs to be precompiled so these tools can parse it. In addition, we need to generate type definition files for TypeScript etc.To handle such multiple targets, one solution could is to have multiple babel configs (or TypeScript configs) and have a babel-cli command in our package.json for compilation. Ideally, we should also keep the configs in sync between our several projects.As an example, this is a command that we had in one of the packages:\nbabel --extensions '.js,.ts,.tsx' --no-babelrc --config-file=./babel.config.publish.js src --ignore '**/__tests__/**' --copy-files --source-maps --delete-dir-on-start --out-dir dist && del-cli 'dist/**/__tests__' && yarn tsc --emitDeclarationOnly\nAs you can see, it's quite long and hard to read. There's even a separate babel.config.publish.js file. And this only works for webpack and Metro, and will fail on Node due to ESM usage.react-native-builder-bob wraps tools such as babel and typescript to simplify these common tasks across multiple projects. While it can be used for any library, it's primarily tailored to React Native projects to minimize the configuration required.","how-do-i-add-a-react-native-library-containing-native-code-as-a-dependency-in-my-library#How do I add a react-native library containing native code as a dependency in my library?":"If your library depends on another react-native library containing native code, you should do the following:\nAdd the native library to peerDependenciesThis means that the consumer of the library will need to install the native library and add it to the dependencies section of their package.json. It makes sure that:\nThere are no version conflicts if another package also happens to use the same library, or if the user wants to use the library in their app. While there can be multiple versions of a JavaScript-only library, there can only be one version of a native library - so avoiding version conflicts is important.\nThe package manager installs it in correct location so that autolinking can work properly.\nDon't add the native library to dependencies of your library, otherwise it may cause issues for the user even if it seems to work.\nAdd the native library to devDependenciesThis makes sure that you can use it for tests, and there are no other errors such as type errors due to the missing module.\nAdd the native library to dependencies in the package.json under exampleThis is equivalent to the consumer of the library installing the dependency, and is needed so that this module is also available to the example app.","how-to-upgrade-the-react-native-version-in-the-generated-project#How to upgrade the react-native version in the generated project?":"Since this is a library, the react-native version specified in the package.json is not relevant for the consumers. It's only used for developing and testing the library. If you'd like to upgrade the react-native version to test with it, you'd need to:\nBump versions of the following packages under devDependencies in the package.json:\nreact-native\nreact\n@types/react\n@types/react-native\nIf you have any other related packages such as react-test-renderer, make sure to bump them as well.\nUpgrade react-native in the example appThe example app is a React Native app that can be updated following the same process as a regular React Native app. The process will vary depending on if it's using Expo or React Native CLI. See the official upgrade guide for more details.\nTo avoid issues, make sure that the versions of react and react-native are the same in example/package.json and the package.json at the root.","how-does-the-library-get-linked-to-the-example-app-in-the-generated-project#How does the library get linked to the example app in the generated project?":"If you generate a project with create-react-native-library, you get an example app to test your library. It's good to understand how the library gets linked to the example app in case you want to tweak how it works or if you run into issues.There are 2 parts to this process.\nAliasing the JavaScript codeThe JavaScript (or TypeScript) source code is aliased to be used by the example app. This makes it so that when you import from 'your-library-name', it imports the source code directly and avoids having to rebuild the library for JavaScript only changes. We configure several tools to make this work:\nBabel is configured to use the alias in example/babel.config.js using babel-plugin-module-resolver. This transforms the imports to point to the source code instead.\nMetro is configured to allow importing from outside of the example directory by configuring watchFolders, and to use the appropriate peer dependencies. This configuration exists in the example/metro.config.js file.\nWebpack is configured to compile the library source code when running on the Web. This configuration exists in the example/webpack.config.js file.\nTypeScript is configured to use the source code for type checking by using the paths property under compilerOptions. This configuration exists in the tsconfig.json file at the root.\nLinking the native codeBy default, React Native CLI only links the modules installed under node_module of the app. To be able to link the android and ios folders from the project root, the path is specified in the example/react-native.config.js file.","how-to-test-the-library-in-an-app-locally#How to test the library in an app locally?":"You may have come across the yarn link and npm link commands, or used npm install ../path/to/folder or yarn add ../path/to/folder to test libraries locally. These commands may work for simple packages without build process, but they have different behavior from how a published package works, e.g. .npmignore is not respected, the structure of node_modules is different, etc. So we don't recommended using these approaches to test libraries locally.For more accurate testing, there are various other approaches:\nLocal tarball with npmFirst, temporarily change the version in package.json to something like 0.0.0-local.0. This version number needs to be updated to something different every time you do this to avoid stale content.Run the following command inside your library's root:\nnpm pack\nThis will generate a file like your-library-name-0.0.0-local.0.tgz in the root of the project.Then, you can install the tarball in your app:\nyarn add ../path/to/your-library-name-0.0.0-local.0.tgz\nOr if you use npm:\nnpm install ../path/to/your-library-name-0.0.0-local.0.tgz\nYalcYalc acts as a local repository for packages that can be used to test packages locally. It's similar to the previous workflow, but more convenient to use.You can find installation and usage instructions in the Yalc documentation.\nVerdaccioVerdaccio is a lightweight private npm registry that can be used to test packages locally. The advantage of using Verdaccio is that it allows to test the complete workflow of publishing and installing a package without actually publishing it to a remote registry.You can find installation and usage instructions in the Verdaccio documentation.","users-get-a-warning-when-they-install-my-library#Users get a warning when they install my library":"If users are using Yarn 1, they may get a warning when installing your library:\nwarning Workspaces can only be enabled in private projects.\nThis is because the example app is configured as a Yarn workspace, and there is a bug in Yarn 1 which causes this warning to be shown for third-party packages. It has no impact for the consumers of the library and the warning can be ignored. If consumers would like to get rid of the warning, there are 2 options:\nDisable workspacesIf the consumer doesn't use Yarn workspaces, they can disable it by adding the following to the .yarnrc file in the root of their project:\nworkspaces-experimental false\nUpgrade to Yarn 3Yarn 1 is no longer maintained, so it's recommended to upgrade to Yarn 3. Yarn 3 works with React Native projects with the node-modules linker. To upgrade, consumers can follow the official upgrade guide.It's also necessary to use node-modules linker. To use it, consumers can add the following to the .yarnrc.yml file in the root of their project:\nnodeLinker: node-modules"}},"/":{"title":"Introduction","data":{"":"This project is a collection of tools to make it easier to build React Native libraries. It contains the following CLIs:\ncreate-react-native-library - a CLI to scaffold a React Native library.\nreact-native-builder-bob - a CLI to build React Native libraries for various targets."}}} \ No newline at end of file diff --git a/_next/static/chunks/pages/create-3327154f5dabf16e.js b/_next/static/chunks/pages/create-3327154f5dabf16e.js new file mode 100644 index 000000000..d2b9f886b --- /dev/null +++ b/_next/static/chunks/pages/create-3327154f5dabf16e.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[417],{2599:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/create",function(){return a(5917)}])},5917:function(e,t,a){"use strict";a.r(t),a.d(t,{__toc:function(){return c},default:function(){return p}});var r=a(4246),n=a(9304),i=a(2917),s=a(6282);a(6288);var l=a(1441),o={src:"/react-native-builder-bob//_next/static/media/create-react-native-library.eafc048f.svg",height:581,width:840,blurWidth:0,blurHeight:0};let c=[{depth:2,value:"Features",id:"features"},{depth:2,value:"Usage",id:"usage"},{depth:2,value:"Local library",id:"local-library"},{depth:2,value:"Writing native code",id:"writing-native-code"}];function d(e){let t=Object.assign({h1:"h1",p:"p",code:"code",h2:"h2",ul:"ul",li:"li",a:"a",pre:"pre",span:"span",img:"img"},(0,l.a)(),e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{children:"Scaffold a React Native library"}),"\n",(0,r.jsxs)(t.p,{children:["If you want to create your own React Native library, scaffolding the project can be a daunting task. ",(0,r.jsx)(t.code,{children:"create-react-native-library"})," can scaffold a new project for you with all the necessary tools configured."]}),"\n",(0,r.jsx)(t.h2,{id:"features",children:"Features"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:"Minimal boilerplate for libraries on which you can build upon"}),"\n",(0,r.jsx)(t.li,{children:"Example React Native app to test your library code"}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"})," to ensure type-safe code and better DX"]}),"\n",(0,r.jsxs)(t.li,{children:["Support for ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules",children:"Turbo Modules"})," & ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/next/the-new-architecture/pillars-fabric-components",children:"Fabric"})]}),"\n",(0,r.jsxs)(t.li,{children:["Support for ",(0,r.jsx)(t.a,{href:"https://kotlinlang.org/",children:"Kotlin"})," on Android & ",(0,r.jsx)(t.a,{href:"https://developer.apple.com/swift/",children:"Swift"})," on iOS"]}),"\n",(0,r.jsx)(t.li,{children:"Support for C++ to write cross-platform native code"}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://expo.io/",children:"Expo"})," for libraries without native code and web support"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://eslint.org/",children:"ESLint"}),", ",(0,r.jsx)(t.a,{href:"https://prettier.io/",children:"Prettier"}),", ",(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"}),", ",(0,r.jsx)(t.a,{href:"https://github.com/evilmartians/lefthook",children:"Lefthook"})," and ",(0,r.jsx)(t.a,{href:"https://github.com/release-it/release-it",children:"Release It"})," pre-configured"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"./build",children:(0,r.jsx)(t.code,{children:"react-native-builder-bob"})})," pre-configured to compile your files"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/features/actions",children:"GitHub Actions"})," pre-configured to run tests and lint on the CI"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.p,{children:"To create new project, run the following:"}),"\n",(0,r.jsx)(t.pre,{"data-language":"sh","data-theme":"default",children:(0,r.jsx)(t.code,{"data-language":"sh","data-theme":"default",children:(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"create-react-native-library@latest"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"awesome-library"})]})})}),"\n",(0,r.jsxs)(t.p,{children:["This will ask you a few questions about your project and generate a new project in a folder named ",(0,r.jsx)(t.code,{children:"awesome-library"}),"."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"Demo",src:o})}),"\n",(0,r.jsxs)(t.p,{children:["After the project is created, you can find the development workflow in the generated ",(0,r.jsx)(t.code,{children:"CONTRIBUTING.md"})," file."]}),"\n",(0,r.jsx)(t.h2,{id:"local-library",children:"Local library"}),"\n",(0,r.jsx)(t.p,{children:"While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app."}),"\n",(0,r.jsxs)(t.p,{children:["If you run ",(0,r.jsx)(t.code,{children:"create-react-native-library"})," in an existing project containing a ",(0,r.jsx)(t.code,{children:"package.json"}),", it'll be automatically detected and you'll be asked if you want to create a local library. You can also pass the ",(0,r.jsx)(t.code,{children:"--local"})," flag to the command to explicitly create a local library:"]}),"\n",(0,r.jsx)(t.pre,{"data-language":"sh","data-theme":"default",children:(0,r.jsx)(t.code,{"data-language":"sh","data-theme":"default",children:(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"create-react-native-library@latest"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"awesome-library"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"--local"})]})})}),"\n",(0,r.jsxs)(t.p,{children:["The local library is created outside of the ",(0,r.jsx)(t.code,{children:"android"})," and ",(0,r.jsx)(t.code,{children:"ios"})," folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in ",(0,r.jsx)(t.a,{href:"https://reactnative.dev",children:"React Native docs"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"The advantages of this approach are:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:["It's easier to upgrade React Native as you don't need to worry about custom code in ",(0,r.jsx)(t.code,{children:"android"})," and ",(0,r.jsx)(t.code,{children:"ios"})," folders."]}),"\n",(0,r.jsxs)(t.li,{children:["It can be used with ",(0,r.jsx)(t.a,{href:"https://expo.io/",children:"Expo"})," managed projects with custom development client."]}),"\n",(0,r.jsx)(t.li,{children:"It's easier to copy the library to other projects or publish later if needed."}),"\n",(0,r.jsx)(t.li,{children:"The boilerplate for the library doesn't need to be written from scratch."}),"\n",(0,r.jsx)(t.li,{children:"It can be used with monorepos where the additional tooling in the default templates may not be needed."}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:["By default, the generated library is automatically linked to the project using ",(0,r.jsx)(t.code,{children:"link:"})," protocol when using ",(0,r.jsx)(t.a,{href:"https://yarnpkg.com/",children:"Yarn"})," and ",(0,r.jsx)(t.code,{children:"file:"})," when using ",(0,r.jsx)(t.a,{href:"https://docs.npmjs.com/cli",children:"npm"}),":"]}),"\n",(0,r.jsx)(t.pre,{"data-language":"json","data-theme":"default",children:(0,r.jsxs)(t.code,{"data-language":"json","data-theme":"default",children:[(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"dependencies"'}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:": {"})]}),"\n",(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-keyword)"},children:'"react-native-awesome-library"'}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"link:./modules/awesome-library"'})]}),"\n",(0,r.jsx)(t.span,{className:"line",children:(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),"\n",(0,r.jsxs)(t.p,{children:["This creates a symlink to the library under ",(0,r.jsx)(t.code,{children:"node_modules"})," which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup."]}),"\n",(0,r.jsx)(t.h2,{id:"writing-native-code",children:"Writing native code"}),"\n",(0,r.jsx)(t.p,{children:"Once the project is created, you can follow the official React Native docs to learn the API for writing native modules and components:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/native-modules-intro",children:"Native Modules"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/native-components-android",children:"Native UI Components for Android"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/native-components-ios",children:"Native UI Components for iOS"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/the-new-architecture/pillars-turbomodules",children:"Turbo Modules"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/the-new-architecture/pillars-fabric-components",children:"Fabric Components"})}),"\n"]})]})}let h={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:t}=Object.assign({},(0,l.a)(),e.components);return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)},pageOpts:{filePath:"pages/create.md",route:"/create",pageMap:[{kind:"Meta",data:{index:"Introduction",create:"Scaffold a library",build:"Build a library",faq:"FAQ"}},{kind:"MdxPage",name:"build",route:"/build"},{kind:"MdxPage",name:"create",route:"/create"},{kind:"MdxPage",name:"faq",route:"/faq"},{kind:"MdxPage",name:"index",route:"/"}],flexsearch:{codeblocks:!0},title:"Scaffold a React Native library",headings:c},pageNextRoute:"/create",nextraLayout:i.ZP,themeConfig:s.Z};var p=(0,n.j)(h)},6282:function(e,t,a){"use strict";var r=a(4246);a(7378),t.Z={primaryHue:30,logo:(0,r.jsx)("span",{style:{fontSize:"32px"},children:"\uD83D\uDC77‍♂️"}),project:{link:"https://github.com/callstack/react-native-builder-bob"},docsRepositoryBase:"https://github.com/callstack/react-native-builder-bob/tree/main/docs",head:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("meta",{name:"viewport",content:"width=device-width, initial-scale=1.0"}),(0,r.jsx)("meta",{property:"og:description",content:"Bob - Create and build React Native libraries with ease"})]}),faviconGlyph:"\uD83D\uDC77‍♂️",footer:{text:(0,r.jsxs)("span",{children:["Copyright \xa9 ",new Date().getFullYear()," ",(0,r.jsx)("a",{href:"https://www.callstack.com/",target:"_blank",rel:"noreferrer",children:"Callstack Open Source"}),"."]})},useNextSeoProps:()=>({titleTemplate:"%s – Bob"})}}},function(e){e.O(0,[774,571,888,179],function(){return e(e.s=2599)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/_next/static/chunks/pages/create-e3c0335e505fe47e.js b/_next/static/chunks/pages/create-e3c0335e505fe47e.js deleted file mode 100644 index e937aa084..000000000 --- a/_next/static/chunks/pages/create-e3c0335e505fe47e.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[417],{2599:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/create",function(){return a(5917)}])},5917:function(e,t,a){"use strict";a.r(t),a.d(t,{__toc:function(){return c},default:function(){return p}});var r=a(4246),n=a(9304),i=a(2917),s=a(6282);a(6288);var l=a(1441),o={src:"/react-native-builder-bob//_next/static/media/create-react-native-library.eafc048f.svg",height:581,width:840,blurWidth:0,blurHeight:0};let c=[{depth:2,value:"Features",id:"features"},{depth:2,value:"Usage",id:"usage"},{depth:2,value:"Local library",id:"local-library"}];function d(e){let t=Object.assign({h1:"h1",p:"p",code:"code",h2:"h2",ul:"ul",li:"li",a:"a",pre:"pre",span:"span",img:"img"},(0,l.a)(),e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{children:"Scaffold a React Native library"}),"\n",(0,r.jsxs)(t.p,{children:["If you want to create your own React Native library, scaffolding the project can be a daunting task. ",(0,r.jsx)(t.code,{children:"create-react-native-library"})," can scaffold a new project for you with all the necessary tools configured."]}),"\n",(0,r.jsx)(t.h2,{id:"features",children:"Features"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:"Minimal boilerplate for libraries on which you can build upon"}),"\n",(0,r.jsx)(t.li,{children:"Example React Native app to test your library code"}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"})," to ensure type-safe code and better DX"]}),"\n",(0,r.jsxs)(t.li,{children:["Support for ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules",children:"Turbo Modules"})," & ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/docs/next/the-new-architecture/pillars-fabric-components",children:"Fabric"})]}),"\n",(0,r.jsxs)(t.li,{children:["Support for ",(0,r.jsx)(t.a,{href:"https://kotlinlang.org/",children:"Kotlin"})," on Android & ",(0,r.jsx)(t.a,{href:"https://developer.apple.com/swift/",children:"Swift"})," on iOS"]}),"\n",(0,r.jsx)(t.li,{children:"Support for C++ to write cross-platform native code"}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://expo.io/",children:"Expo"})," for libraries without native code and web support"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://eslint.org/",children:"ESLint"}),", ",(0,r.jsx)(t.a,{href:"https://prettier.io/",children:"Prettier"}),", ",(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"}),", ",(0,r.jsx)(t.a,{href:"https://github.com/evilmartians/lefthook",children:"Lefthook"})," and ",(0,r.jsx)(t.a,{href:"https://github.com/release-it/release-it",children:"Release It"})," pre-configured"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"./build",children:(0,r.jsx)(t.code,{children:"react-native-builder-bob"})})," pre-configured to compile your files"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/features/actions",children:"GitHub Actions"})," pre-configured to run tests and lint on the CI"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.p,{children:"To create new project, run the following:"}),"\n",(0,r.jsx)(t.pre,{"data-language":"sh","data-theme":"default",children:(0,r.jsx)(t.code,{"data-language":"sh","data-theme":"default",children:(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"create-react-native-library@latest"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"awesome-library"})]})})}),"\n",(0,r.jsxs)(t.p,{children:["This will ask you a few questions about your project and generate a new project in a folder named ",(0,r.jsx)(t.code,{children:"awesome-library"}),"."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"Demo",src:o})}),"\n",(0,r.jsxs)(t.p,{children:["After the project is created, you can find the development workflow in the generated ",(0,r.jsx)(t.code,{children:"CONTRIBUTING.md"})," file."]}),"\n",(0,r.jsx)(t.h2,{id:"local-library",children:"Local library"}),"\n",(0,r.jsxs)(t.p,{children:["While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app. The local library is created outside of the ",(0,r.jsx)(t.code,{children:"android"})," and ",(0,r.jsx)(t.code,{children:"ios"})," folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in ",(0,r.jsx)(t.a,{href:"https://reactnative.dev",children:"React Native docs"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["If you run ",(0,r.jsx)(t.code,{children:"create-react-native-library"})," in an existing project containing a ",(0,r.jsx)(t.code,{children:"package.json"}),", it'll be automatically detected and you'll be asked if you want to create a local library. You can also pass the ",(0,r.jsx)(t.code,{children:"--local"})," flag to the command to explicitly create a local library:"]}),"\n",(0,r.jsx)(t.pre,{"data-language":"sh","data-theme":"default",children:(0,r.jsx)(t.code,{"data-language":"sh","data-theme":"default",children:(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"create-react-native-library@latest"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"awesome-library"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string)"},children:"--local"})]})})}),"\n",(0,r.jsx)(t.p,{children:"The advantages of this approach are:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:["It's easier to upgrade React Native as you don't need to worry about custom code in ",(0,r.jsx)(t.code,{children:"android"})," and ",(0,r.jsx)(t.code,{children:"ios"})," folders."]}),"\n",(0,r.jsxs)(t.li,{children:["It can be used with ",(0,r.jsx)(t.a,{href:"https://expo.io/",children:"Expo"})," managed projects with custom development client."]}),"\n",(0,r.jsx)(t.li,{children:"It's easier to copy the library to other projects or publish later if needed."}),"\n",(0,r.jsx)(t.li,{children:"The boilerplate for the library doesn't need to be written from scratch."}),"\n",(0,r.jsx)(t.li,{children:"It can be used with monorepos where the additional tooling in the default templates may not be needed."}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:["By default, the generated library is automatically linked to the project using ",(0,r.jsx)(t.code,{children:"link:"})," protocol when using ",(0,r.jsx)(t.a,{href:"https://yarnpkg.com/",children:"Yarn"})," and ",(0,r.jsx)(t.code,{children:"file:"})," when using ",(0,r.jsx)(t.a,{href:"https://docs.npmjs.com/cli",children:"npm"}),":"]}),"\n",(0,r.jsx)(t.pre,{"data-language":"json","data-theme":"default",children:(0,r.jsxs)(t.code,{"data-language":"json","data-theme":"default",children:[(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"dependencies"'}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:": {"})]}),"\n",(0,r.jsxs)(t.span,{className:"line",children:[(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-keyword)"},children:'"react-native-awesome-library"'}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,r.jsx)(t.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"link:./modules/awesome-library"'})]}),"\n",(0,r.jsx)(t.span,{className:"line",children:(0,r.jsx)(t.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),"\n",(0,r.jsxs)(t.p,{children:["This creates a symlink to the library under ",(0,r.jsx)(t.code,{children:"node_modules"})," which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup."]})]})}let h={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:t}=Object.assign({},(0,l.a)(),e.components);return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)},pageOpts:{filePath:"pages/create.md",route:"/create",pageMap:[{kind:"Meta",data:{index:"Introduction",create:"Scaffold a library",build:"Build a library",faq:"FAQ"}},{kind:"MdxPage",name:"build",route:"/build"},{kind:"MdxPage",name:"create",route:"/create"},{kind:"MdxPage",name:"faq",route:"/faq"},{kind:"MdxPage",name:"index",route:"/"}],flexsearch:{codeblocks:!0},title:"Scaffold a React Native library",headings:c},pageNextRoute:"/create",nextraLayout:i.ZP,themeConfig:s.Z};var p=(0,n.j)(h)},6282:function(e,t,a){"use strict";var r=a(4246);a(7378),t.Z={primaryHue:30,logo:(0,r.jsx)("span",{style:{fontSize:"32px"},children:"\uD83D\uDC77‍♂️"}),project:{link:"https://github.com/callstack/react-native-builder-bob"},docsRepositoryBase:"https://github.com/callstack/react-native-builder-bob/tree/main/docs",head:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("meta",{name:"viewport",content:"width=device-width, initial-scale=1.0"}),(0,r.jsx)("meta",{property:"og:description",content:"Bob - Create and build React Native libraries with ease"})]}),faviconGlyph:"\uD83D\uDC77‍♂️",footer:{text:(0,r.jsxs)("span",{children:["Copyright \xa9 ",new Date().getFullYear()," ",(0,r.jsx)("a",{href:"https://www.callstack.com/",target:"_blank",rel:"noreferrer",children:"Callstack Open Source"}),"."]})},useNextSeoProps:()=>({titleTemplate:"%s – Bob"})}}},function(e){e.O(0,[774,571,888,179],function(){return e(e.s=2599)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/build.html b/build.html index 6ac03aa2b..5d46fcb74 100644 --- a/build.html +++ b/build.html @@ -11,7 +11,7 @@ --nextra-primary-hue: 30deg; --nextra-primary-saturation: 100%; } -
Build a library

Build a React Native library

+
Build a library

Build a React Native library

When code is in non-standard syntaxes such as JSX, TypeScript etc, it needs to be compiled before it can run. Configuring this manually can be error-prone and annoying. react-native-builder-bob aims to simplify this process by wrapping babel and tsc and taking care of the configuration. See this section for a longer explanation.

Supported targets are:

    @@ -158,4 +158,4 @@

    "scripts": {
       "prepare": "bob build"
     }

-

Demo

\ No newline at end of file +

Demo

\ No newline at end of file diff --git a/create.html b/create.html index 4dd1ec170..4d3fe63be 100644 --- a/create.html +++ b/create.html @@ -11,7 +11,7 @@ --nextra-primary-hue: 30deg; --nextra-primary-saturation: 100%; } -
Scaffold a library

Scaffold a React Native library

+
Scaffold a library

Scaffold a React Native library

If you want to create your own React Native library, scaffolding the project can be a daunting task. create-react-native-library can scaffold a new project for you with all the necessary tools configured.

Features

    @@ -33,9 +33,10 @@

    Demo

    After the project is created, you can find the development workflow in the generated CONTRIBUTING.md file.

    Local library

    -

    While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app. The local library is created outside of the android and ios folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in React Native docs (opens in a new tab).

    +

    While the default templates are for libraries that are published to npm, you can also create a local library that is not published, but used locally in your app.

    If you run create-react-native-library in an existing project containing a package.json, it'll be automatically detected and you'll be asked if you want to create a local library. You can also pass the --local flag to the command to explicitly create a local library:

    npx create-react-native-library@latest awesome-library --local
    +

    The local library is created outside of the android and ios folders and makes use of autolinking to integrate with your app. It also doesn't include a separate example app and additional dependencies that are configured in the default templates. This is an alternative approach to the setup mentioned in React Native docs (opens in a new tab).

    The advantages of this approach are:

    • It's easier to upgrade React Native as you don't need to worry about custom code in android and ios folders.
    • @@ -48,4 +49,13 @@

      "dependencies": {
         "react-native-awesome-library": "link:./modules/awesome-library"
       }

-

This creates a symlink to the library under node_modules which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup.

\ No newline at end of file +

This creates a symlink to the library under node_modules which makes autolinking work. But if you're using a monorepo or have non-standard setup, you'll need to manually set up the package to be linked to your app based on your project setup.

+

Writing native code

+

Once the project is created, you can follow the official React Native docs to learn the API for writing native modules and components:

+
\ No newline at end of file diff --git a/faq.html b/faq.html index bf1f939cc..259232241 100644 --- a/faq.html +++ b/faq.html @@ -11,7 +11,7 @@ --nextra-primary-hue: 30deg; --nextra-primary-saturation: 100%; } -
FAQ

Frequently Asked Questions

+
FAQ

Frequently Asked Questions

Why should I compile my project with react-native-builder-bob?

We often write our library code in non-standard syntaxes such as JSX, TypeScript etc. as well as proposed syntaxes which aren't part of the standard yet. This means that our code needs to be compiled to be able to run on JavaScript engines.

When using the library in a React Native app, Metro handles compiling the source code. However, it's also possible to use them in other targets such as:

@@ -126,4 +126,4 @@

It's also necessary to use node-modules linker. To use it, consumers can add the following to the .yarnrc.yml file in the root of their project:

nodeLinker: node-modules
-

\ No newline at end of file +
\ No newline at end of file diff --git a/index.html b/index.html index cb10ccd97..bb07896bc 100644 --- a/index.html +++ b/index.html @@ -11,9 +11,9 @@ --nextra-primary-hue: 30deg; --nextra-primary-saturation: 100%; } -
Introduction

Introduction

+
\ No newline at end of file +
\ No newline at end of file