React in Docker with Nginx, built with multi-stage Docker builds, including testing

React in Docker with Nginx, built with multi-stage Docker builds, including testing

When you build a React front-end app, you most commonly write it in modern JavaScript (ECMAScript 2015) and then compile it to older, backward compatible, versions of JavaScript, to make sure it runs on all the browsers that you want to support. But you need to have Node.js and several packages to do that.

[…]

We are getting close, but you would have another complex script to debug. Copying files from a Docker container and to another Docker image, etc. Not that promising…

[…]

If you don’t know React yet, go and do their tutorial first.

[…]

The same way that you would add node_modules to your .gitignore file, you can use a .dockerignore file to tell Docker that it shouldn't "send" that directory.

[…]

…that’s it for the Dockerfile! Doing that with scripts or any other method would be a lot more cumbersome.

[…]

If you are using testing, for example with Jest, as is the default with create-react-app, you can run your tests during your Docker image building, adding the commands to your Dockerfile.

[…]

The application generated with create-react-app comes with Jest testing. You can run the tests locally before building the Docker image, with:

[…]