Create React App inside a non-empty folder
Created by: erdemkeren
I use create-react-app
to create a react app inside an existing backend project which will serve the react application. And I have to run the eject
command to:
- change the target directory
- change the build logic and directories
- add
.less
support with some extra configuration and so on...
To automate this process, I took a fork from react-scripts
and I defined my folder structure. A
My final file system hierarchy should be something like:
- project directory
- foo
- bar
- baz
- resources
- react-app
- index.js
- package.json
- qux.php
So I edited the template folder to match these requirements and published the scripts to give a try.
npx create-react-app . --scripts-version my-react-scripts
And as you guessed, I got
The directory . contains files that could conflict: Backend FSH.
However:
- I need my
package.json
to be located in the project root directory. - My scripts will create a new directory called
react-app
inside the existingresources
folder. And react-app will live inside this directory. I don't expect an override. - My build is customized and will use my webpack plugin to generate the built files. I don't expect an unexpected override here as well.
Describe the solution you'd like
- Since I know what I do, I want to have some way to run
create-react-app
in an existing folder with some files.
Maybe by setting a constant from my scripts or using an option after npx create-react-app
call.
Describe alternatives you've considered
I considered to update create-react-app to support it as well but that doesn't make sense since it would be almost impossible to follow up the updates and upgrades later.
Additional context
https://github.com/facebook/create-react-app/issues/334 https://github.com/facebook/create-react-app/issues/2776