Skip to content

Commit

Permalink
coordinate frontend and backend in production build
Browse files Browse the repository at this point in the history
  • Loading branch information
tanqiuliu committed Apr 6, 2020
1 parent cf1a3af commit 2ffe30c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# spring-react-typescript-boilerplate
A boilerplate for spring boot web application with a frontend developed in react & typescript

Combining [kantega's approach](https://github.com/kantega/react-and-spring) with this [react-typescript0-starter](https://github.com/deepwaterL/react-typescript-boilerplate).
19 changes: 18 additions & 1 deletion frontend/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ import '../styles/index.css';

export interface IAppProps {}

export interface IAppState {}
export interface IAppState {
response: string
}

class App extends React.PureComponent<IAppProps, IAppState> {

constructor(props: IAppProps) {
super(props);
this.state = {response: 'Loading'};
}

componentDidMount(): void {
fetch('api/hello')
.then(response => response.text())
.then(text => {
this.setState({response: text});
});
}

render() {
return (
<div>
<h1>Hello World!</h1>
<p>{this.state.response}</p>
</div>
);
}
Expand Down
59 changes: 59 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Install node, npm and build frontend -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>frontend</workingDirectory>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v12.3.1</nodeVersion>
<npmVersion>6.14.2</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Copy the production build into target -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/public">
<fileset dir="${project.basedir}/frontend/dist"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit 2ffe30c

Please sign in to comment.