20
votes

I have a folder setup with some files I already want to have in the folder. I want to be able to run

react-native init PROJECTNAME

and instead of creating a folder PROJECTNAME it would init a react-native project in the folder I am currently in.

Is this possible?


Currently, I have my setup already created from previous projects that I enjoy using (packages.json, config files, etc). I delete the node_modules, and then react-native init PROJECTNAME. Then I take the PROJECTNAME/ios PROJECTNAME/android folders generated within that folder, move them into the main project folder and it works pretty smoothly. Just not optimal.

4
I'm also creating the project and manually moving the files. If you already had a build then I found I also needed to clear the cache ./node_modules/react-native/packager/packager.sh clean - agtb
would be nice to make a script out of this, or nice if react-native could update their cmd line to accept this setup :) - Austin Witherow
Yep, especially if you created the repo first. - developarvin

4 Answers

23
votes

You can do

$ cd .. && react-native init folder_name

It will overwrite your package.json but keep the non-default files.

1
votes

This issue is currently tracked there.

0
votes

The reason I wanted to do this was to have a sort of mono-repo, but I have transitioned away from this approach as I am not sure it is beneficial.

0
votes

You should have install react-native-cli instead of react-native globally as described here.

And then the command is:

npx react-native-cli init appname --directory ./appPathToDir