I have made a few simple reusable react components and wanted to know the correct way to include a dependency to react in my package.json for publishing with npm.
I am currently doing this:
Assuming my component will use the most recent version of react and I have tested and it works with that version. e.g. 0.13.3
"peerDependencies": { "react": "^0.13.3" },
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
For reusable components:
react
dependency in both peerDependencies
and devDependencies
.react
dependency in dependencies
.peerDependencies
specifies which version(s) of React your reusable component supports/requires. When using npm 2 this also adds React to the list of modules to be installed, but this is no longer the case with npm 3.
devDependencies
ensures React will be installed when you run npm install
while developing your component, or when running tests on Travis or similar.
Putting react
in dependencies
will cause multiple versions of React to be installed if somebody uses your component but has a different version of React in their own package.json
- having multiple versions of React not only bloats the build, but also causes errors when different versions try to interact.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With