All Projects → pugnascotia → Spring React Boilerplate

pugnascotia / Spring React Boilerplate

Licence: mit
An example of an isomorphic application using Java + Spring with React, React Router and Redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Spring React Boilerplate

Universal Native Boilerplate
Build apps for every native platform with React and React Native
Stars: ✭ 131 (-16.03%)
Mutual labels:  webpack, boilerplate
Project Webcube
Continuously updated JS infrastructure for modern web dev
Stars: ✭ 141 (-9.62%)
Mutual labels:  webpack, boilerplate
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: ✭ 134 (-14.1%)
Mutual labels:  webpack, boilerplate
React Boilerplate
React Boilerplate
Stars: ✭ 128 (-17.95%)
Mutual labels:  webpack, boilerplate
React Redux Styled Hot Universal
react boilerplate used best practices and focus on performance
Stars: ✭ 147 (-5.77%)
Mutual labels:  webpack, boilerplate
Koa React Isomorphic
Boilerplate for Koa & React
Stars: ✭ 128 (-17.95%)
Mutual labels:  webpack, boilerplate
Eleventy Starter Boilerplate
🚀 Eleventy Starter is production-ready with SEO-friendly for quickly starting a blog. ⚡ Built with Eleventy, ESLint, Prettier, Webpack, PostCSS, Tailwind CSS and Netlify CMS (optional).
Stars: ✭ 139 (-10.9%)
Mutual labels:  webpack, boilerplate
Serverless Prisma
AWS Serverless Prisma Boilerplate
Stars: ✭ 126 (-19.23%)
Mutual labels:  webpack, boilerplate
Awesome Chrome Extension Boilerplate
Use react + typescript + webpack to enhance your chrome extension development experience
Stars: ✭ 146 (-6.41%)
Mutual labels:  webpack, boilerplate
Js Stack Boilerplate
Final boilerplate code of the JavaScript Stack from Scratch tutorial –
Stars: ✭ 145 (-7.05%)
Mutual labels:  webpack, boilerplate
Create Elm App
🍃 Create Elm apps with zero configuration
Stars: ✭ 1,650 (+957.69%)
Mutual labels:  webpack, boilerplate
React Webpack 5 Tailwind 2
React 17 Boilerplate with Webpack 5, Tailwind 2, using babel, SASS/PostCSS, HMR, dotenv and an optimized production build
Stars: ✭ 155 (-0.64%)
Mutual labels:  webpack, boilerplate
React Redux Graphql Apollo Bootstrap Webpack Starter
react js + redux + graphQL + Apollo + react router + hot reload + devTools + bootstrap + webpack starter
Stars: ✭ 127 (-18.59%)
Mutual labels:  webpack, boilerplate
Webpack Starter
✨ A lightweight foundation for your next webpack based frontend project.
Stars: ✭ 1,745 (+1018.59%)
Mutual labels:  webpack, boilerplate
Koa Vue Fullstack
A lightweight boilerplate for a universal webapp based on koa, mongodb, node, vue, and webpack
Stars: ✭ 126 (-19.23%)
Mutual labels:  webpack, boilerplate
Redux React Starter
DEPRECATED use the new https://github.com/didierfranc/react-webpack-4
Stars: ✭ 137 (-12.18%)
Mutual labels:  webpack, boilerplate
Razzle Material Ui Styled Example
Razzle Material-UI example with Styled Components using Express with compression
Stars: ✭ 117 (-25%)
Mutual labels:  webpack, boilerplate
Static Site Boilerplate
A better workflow for building modern static websites.
Stars: ✭ 1,633 (+946.79%)
Mutual labels:  webpack, boilerplate
Iceberg
Front-End Boilerplate built with React + Babel + Webpack + SASS
Stars: ✭ 144 (-7.69%)
Mutual labels:  webpack, boilerplate
Kirby Webpack
💪 A Kirby CMS starter-kit with modern frontend tools
Stars: ✭ 150 (-3.85%)
Mutual labels:  webpack, boilerplate

spring-react-boilerplate

An example application that uses a Spring Java backend with a React frontend and can perform server-side rendering (SSR).

Another Boilerplate?

Yes, but with Java. It's inspired by the spring-react-isomorphic project, but at this point has been largely rebuilt from the ground up. The frontend is build on create-react-app (CRA), though it was necessary to "eject" from CRA in order to apply some changes for server.

The project also uses:

Other Goodies

You also get:

  • Project Lombok to cut down the Java boilerplate
  • Jackson to serialize model data before rendering on the server. For more information, see this OpenJDK thread on the subject, but summary is Nashorn won't (and actually can't) string-ify POJOs via JSON.stringify, meaning it can't be used to serialise the Redux state. Without this you'll have a bad time trying to use your Java objects in your Redux state.

Changes from create-react-app

  • Webpack output is a UMD bundle, which makes it possible to load it in Nashorn
  • Hot reloading has been added
  • LESS support has been added
  • CRA's polyfills.js has been changed to be SSR-friendly
  • Possible to disable uglification during the production build by setting the DEBUG environment variable (see below).

The render function

We implement a custom render function for Spring to call. The source code is in src/main/js/react-render/renderer.js, and is compiled to ES5 syntax during the Maven build. The build process also pulls in polyfills, to allow React etc to work, and also the frontend's JSON manifest, in order to locate the frontend's built assets. See the build.sh in the same directory for how the final render code is assembled.

Running the code

Execute mvn if you have Maven already installed, or ./mvnw if you don't. You'll need Java8 installed either way at a MINIMUM version of 1.8.0_65. Older versions have a bug that makes rendering brutally slow. Note that since React is not thread-safe, Spring is configured to use a script engine per thread, and each one will have to load the bundle when first initialises. You may want to force refresh the website several times to make sure all the threads are initialised, particular if you intend to measure performance.

To run the frontend in hot-module reloading mode, switch to another terminal and execute:

cd src/main/app
yarn start

Your browser should automatically open http://localhost:3000. Now when you edit your files, the changes will be loaded in your browser automatically and, where possible, be applied without losing the application's current state thanks to react-hot-loader!

Conventions

Controllers that render views are suffixed with Controller. REST endpoints are suffixed with Resource and handle requests under /api.

Testing the Webpack bundle / render function

In order to preempt runtime errors with Nashorn loading the bundle, a test script is executed by Maven during the test-compile phase, located at src/test/js/react-renderer/test.js. If this script fails, you can diagnose the problem by running:

DEBUG=true mvn test-compile

This will rebuild the webpack bundle without minification, which should make the cause of any error clearer.

It's easy to create a bundle that's broken on the server by including code that expects a DOM - and that includes the Webpack style loader. This is the root of most problems. You should note that server-side rendering does not require a DOM - which is why src/main/js/react-renderer/polyfill.js doesn't provide any window or document stubs.

Caveats

This isn't necessarily the best way to write a React application or a Spring application. Pull requests welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].