2

I've created an React app with create-react-app and I want to deploy it to Back4App.

The problem is I want to deploy the build folder and not the public folder (which I understand is the default for Back4App / ParsePlatform).

So far, I haven't found any way to config deploy to use anything other than the public folder.

Any solution / workaround to this?

marco alves
  • 1,707
  • 2
  • 18
  • 28
  • all `build` does is create the files and put them in the build folder on your development machine, but they don't have to be in a build folder on your server; you can simply copy the contents of the build folder into the public folder. – Claies Nov 17 '18 at 14:42
  • But it creates kinda of a circular loop as the build process also uses the public folder as source — cleanest way would be to configure the deploy folder to whatever we need – marco alves Nov 17 '18 at 14:58
  • I guess I'm just confused here; it seems as though the workflow for back4app assumes you are going to deploy directly from your source and not use `build` at all. https://www.back4app.com/docs/javascript/react-template – Claies Nov 17 '18 at 15:02
  • 1
    You're right. I'm just double checking if there is any way around it. It would be better for back4app to have `public` as default but let us configure `build` (or other) if required. – marco alves Nov 17 '18 at 18:18

1 Answers1

3

If you are using B4A CLI, one of the easiest ways to deploy a create-react-app is, firstly, changing the build script into your package.json as below snippet:

...
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build && cp -r build/* {{PATH-TO-YOUR-B4A-APP}}/public",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
...

As you can see, you just need to move all content inside create-react-app build folder to the public folder of your cloud code. After that, move to your app path and run b4a deploy.

Also, you could add a step to clear all public folder content before move the new stuff, but be careful with this step.

Otherwise, you could access the Back4app Parse-Dashboard into the Cloud Code Functions and deploy all the build stuff in public folder using the browser interface.

This is a live demo of a create-react-app deployed in Back4App.

Lucas Alencar
  • 350
  • 2
  • 11
  • 2
    Thanks I’m going to try the dashboard option. Changing the build script seems to work just for one deployment as we will lose the default index.html in the public folder after running the first time. Right? – marco alves Dec 09 '18 at 08:46
  • 2
    I've edited the snippet to a better understanding, you'll have two different projects: one is your ReactJS and the other is your Back4App App. So the Build script will move all the built content from your ReactJS project to your cloud code public folder so that the public folder into your ReactJS project will keep the same. It's kind of confused 'cause the folders have the same name, but I hope it is more clear now. – Lucas Alencar Dec 09 '18 at 19:09
  • I get unauthorized when navigating to another page https://react-b4a.back4app.io/rr please how do i resolve that @LucasAlencar? – olawalejuwonm Oct 27 '22 at 21:57