Giter VIP home page Giter VIP logo

spring-boot-with-reactjs's Introduction

This is a sample project that goes along with my Medium article that shows how to build a ReactJS UI and Spring Boot backend with Maven. This Spring Guide provides a similar description of a hybrid technology/build.

Build

To build a jar that includes the production build of the ReactJS code, run

./mvnw package

Bootstrapping your own project like this one

Spring Boot + Maven content

Initialize your project with Spring Initializr or the integration thereof in your favorite IDE.

ReactJS module setup

From a terminal, go into the src/main directory of this project and use create-react-app to bootstrap the ReactJS content:

npx create-react-app ui

In the created ui directory, create the file .env with the content

BUILD_PATH = ../../../target/classes/public

Frontend Maven Plugin setup

In the pom.xml add the following two properties where node.version should be changed to the desired NodeJS version:

    <ui.directory>${project.basedir}/src/main/ui</ui.directory>
    <node.version>16.1.0</node.version>

In the build->plugins section of the pom.xml add the frontend maven plugin with the version updated to the latest:

      <plugin>
        <artifactId>frontend-maven-plugin</artifactId>
        <groupId>com.github.eirslett</groupId>
        <!-- update this version to the latest -->
        <version>1.12.0</version>
  
        <executions>
          
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
          </execution>
          
          <execution>
            <id>react test</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <phase>test</phase>
            <configuration>
              <arguments>test</arguments>
              <workingDirectory>${ui.directory}</workingDirectory>
              <environmentVariables>
                <!-- Enable non-watch mode -->
                <CI>true</CI>
              </environmentVariables>
            </configuration>
          </execution>
          
          <execution>
            <id>react build</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <arguments>run build</arguments>
              <workingDirectory>${ui.directory}</workingDirectory>
            </configuration>
          </execution>
          
        </executions>
    
        <configuration>
          <nodeVersion>v${node.version}</nodeVersion>
          <installDirectory>${project.build.directory}</installDirectory>
        </configuration>
      </plugin>

spring-boot-with-reactjs's People

Contributors

itzg avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.