You can use multi-stage builds [1] so your result image would be as small as possible by just copying the compiled JS from the build stage.
[1]: https://docs.docker.com/develop/develop-images/multistage-bu...
[1]: https://docs.docker.com/develop/develop-images/multistage-bu...
Also you need to keep those huge images, if you want to have any reasonable caching. Otherwise builds will take forever.