jka
jka

Reputation: 457

How to add React to an existing Electron app?

How to add React to an existing Electron app?

I have a CLI Node.js application to which I'm intending to add a desktop GUI using ElectronJS and React. I now have succesfully combined the original CLI app and Electron so that when I run npm start an Electron powered window pops up and the old app starts doing its thing. Is there an easy way to add React to the stack or do I need to start my project over with this new architecture in mind?

Now when I go to the root directory of my project and try to npx create-react-app it refuses to initialize because there's already stuff in there. If I create a new subdirectory to my project in which I would then initialize the React app then I'd have node_modules, package.json etc. duplicates and a weird layered structure which probably isn't the recommended way to go about if it would even work...

Upvotes: 1

Views: 4355

Answers (1)

user13124036
user13124036

Reputation:

Create a subdirectory and run create-react-app there. Afterwards, just move the contents up a directory and delete the empty directory.

Example:

cp package.json package.json.backup
mkdir temp
cd temp
npx create-react-app test-app
mv test-app/* ..
cd ..
rm -fr temp

You can run the above commands in Git Bash if you're on Windows.

Afterwards, you will want to manually merge the package.json from create-react-app with your old one that's now called package.json.backup.

Upvotes: 2

Related Questions