react-native-yarn-workspaces-v2

0.0.2 • Public • Published

react-native-yarn-workspaces-v2

React Native support for Yarn Workspaces.

Note

This package only run on macOs and Linux and haven't tested on ios.
To use this package you have to create the react native project using npx react-native init. If you are using expo, use expo-yarn-workspaces instead.

Inspired by expo-yarn-workspaces. The inner working of this package is same as expo-yarn-workspaces, check it for more details. This package is specifically tweaked to work with bare react-native project.

Installation

Install the package as a dev dependency.

foo@bar:~$ yarn add -D react-native-yarn-workspaces-v2
or
foo@bar:~$ npm i --save-dev react-native-yarn-workspaces-v2

Usage

Add a postinstall script to package.json

Add "postinstall": "react-native-yarn-workspaces-v2" under the script object in the app's package.json.

Modify metro.config.js.

If the file does not exist, create it.

const {
  extraNodeModules,
  watchFolders 
= require('react-native-yarn-workspaces-v2')(__dirname);
 
module.exports = {
  watchFolders,
  resolver: {
    extraNodeModules
  },
  // Generated by `react-native`.
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false
      }
    })
  }
  // end
};

This will tell the metro bundler to look for packages on the yarn workspaces' root node_modules directory and resolve all the symlink to their real path.

Adding additional packages to symlink.

To add additional packages to symlink. Add workspaces-symlink inside package.json with the packages you want to symlink as value (array).

Example:

// package.json
{
  ...
  "workspaces-symlink": [
    "react-native-vector-icons"
  ]
}

(Android)
If you configure react-native-vector-icons.

project.ext.vectoricons = [
   iconFontNames: [ 'MaterialCommunityIcons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

And add the above in your app/build.gradle file it won't work. The fonts.gradle is located at the workspace root node_modules. So, you either have to specify the path to the workspace root node_modules or symlink the package to make it work.

LICENSE

Dependencies (2)

Dev Dependencies (1)

Package Sidebar

Install

npm i react-native-yarn-workspaces-v2

Weekly Downloads

38

Version

0.0.2

License

MIT

Unpacked Size

9.51 kB

Total Files

8

Last publish

Collaborators

  • gyanendrokh