jhipsterSampleApplicationReact

这是使用 React 通过 JHipster 创建的示例应用程序。(This is a sample application created with JHipster, using React)

Github stars Tracking Chart

jhipsterSampleApplicationReact

该应用程序是使用 JHipster 6.10.1 生成的,您可以在 https://www.jhipster.tech/documentation-archive/v6.10.1 中找到文档和帮助。

开发

在生成此项目之前,必须在计算机上安装和配置以下依赖项:

Node.js:我们使用 Node 来运行开发 Web 服务器并构建项目。根据您的系统,您可以从源安装或作为预打包的捆绑包安装 Node。

安装 Node 之后,您应该能够运行以下命令来安装开发工具。当 package.json 中的依赖项发生更改时,您仅需要运行此命令。

npm install

我们使用 npm 脚本和 Webpack 作为构建系统。

在两个独立的终端中运行以下命令,以创建一个愉快的开发体验,其中您的浏览器会在硬盘上的文件更改时自动刷新。

./mvnw
npm start

Npm 还用于管理此应用程序中使用的 CSS 和 JavaScript 依赖项。您可以通过在 package.json 中指定较新的版本来升级依赖项。您还可以运行 npm update 和 npm install 来管理依赖项。在任何命令上添加帮助标志,以查看如何使用它。例如,npm help update。

npm run 命令将列出可用于该项目的所有脚本。

PWA 支持

JHipster 随附 PWA(渐进式 Web 应用程序)支持,并且默认情况下处于关闭状态。 PWA 的主要组成部分之一是 service worker。

默认情况下,service worker 初始化代码被注释掉。要启用它,请在 src/main/webapp/index.html 中取消注释以下代码:

<script>
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('./service-worker.js').then(function () {
      console.log('Service Worker Registered');
    });
  }
</script>

注意:Workbox 为 JHipster 的 service worker 提供了动力。它动态生成 service-worker.js 文件。

管理依赖

例如,要将 Leaflet 库添加为应用程序的运行时依赖项,可以运行以下命令:

npm install --save --save-exact leaflet

要从开发中的 DefinitelyTyped 存储库中受益于 TypeScript 类型定义,可以运行以下命令:

npm install --save-dev --save-exact @types/leaflet

然后,您将导入库的安装说明中指定的 JS 和 CSS 文件,以便 Webpack 知道它们:编辑 src/main/webapp/app/vendor.ts 文件:

import 'leaflet/dist/leaflet.js';

编辑 src/main/webapp/content/scss/vendor.scss 文件;

@import '~leaflet/dist/leaflet.css';

注意:Leaflet 还有其他要做的事情,我们在这里不再详述。

有关如何使用 JHipster 进行开发的更多说明,请参阅在开发中使用 JHipster

使用 Angular CLI

您也可以使用 Angular CLI 生成一些自定义客户端代码。

例如,以下命令:

ng generate component my-component

将生成一些文件:

create src/main/webapp/app/my-component/my-component.component.html
create src/main/webapp/app/my-component/my-component.component.ts
update src/main/webapp/app/app.module.ts

生产构建

打包为 jar

要构建最终的 jar 并优化用于生产的 jhipsterSampleApplication 应用程序,请运行:

./mvnw -Pprod clean verify

这将串联并缩小客户端 CSS 和 JavaScript 文件。它还将修改 index.html,以便它引用这些新文件。为确保一切正常,请运行:

java -jar target/*.jar

然后在浏览器中导航到 http://localhost:8080。

有关更多详细信息,请参阅在生产中使用 JHipster

打包为 war

要将您的应用程序打包为 war 以便将其部署到应用程序服务器,请运行:

./mvnw -Pprod,war clean verify

测试

要启动应用程序的测试,请运行:

./mvnw verify

客户测试

单元测试由 Jest 运行,并由 Jasmine 编写。它们位于 src/test/javascript/ 中,可以与以下命令一起运行:

npm test

有关更多信息,请参阅“运行测试”页面

代码质量

声纳用于分析代码质量。您可以使用以下命令启动本地 Sonar 服务器(可从http://localhost:9001 访问):

docker-compose -f src/main/docker/sonar.yml up -d

您可以使用 sonar-scanner 或 maven 插件运行 Sonar 分析。

然后,运行 Sonar 分析:

./mvnw -Pprod clean verify sonar:sonar

如果需要重新运行 Sonar 阶段,请确保至少指定初始化阶段,因为 Sonar 属性是从 sonar-project.properties 文件加载的。

./mvnw initialize sonar:sonar

有关更多信息,请参阅代码质量页面

使用 Docker 简化开发(可选)

您可以使用 Docker 来改善您的 JHipster 开发体验。 src/main/docker 文件夹中提供了许多 docker-compose 配置,以启动所需的第三方服务。

例如,要在 Docker 容器中启动 mysql 数据库,请运行:

docker-compose -f src/main/docker/mysql.yml up -d

要停止它并删除容器,请运行:

docker-compose -f src/main/docker/mysql.yml down

您还可以对应用程序及其依赖的所有服务进行完全 docker 化。为此,请首先通过运行以下步骤为您的应用构建 docker 映像:

./mvnw -Pprod verify jib:dockerBuild

然后运行:

docker-compose -f src/main/docker/app.yml up -d

有关更多信息,请参阅《使用Docker 和 Docker-Compose》,此页面还包含有关 docker-compose 子生成器(jhipster docker-compose)的信息,该子生成器能够为一个或多个 JHipster 应用程序生成 docker 配置。

持续集成(可选)

要为您的项目配置 CI,请运行 ci-cd 子生成器(jhipster ci-cd),这将使您为许多 Continuous Integration 系统生成配置文件。请参阅“设置持续集成”页面以获取更多信息。


(The first version translated by vz on 2020.08.08)

Overview

Name With Ownerjhipster/jhipster-sample-app-react
Primary LanguageJava
Program languageJava (Language Count: 9)
PlatformDocker, Linux, Mac, Windows
License:Apache License 2.0
Release Count71
Last Release Namev8.4.0 (Posted on )
First Release Namev5.0.0-beta.0 (Posted on 2018-04-03 22:18:33)
Created At2017-12-11 22:14:15
Pushed At2024-04-30 02:27:00
Last Commit At2020-09-20 12:36:55
Stargazers Count213
Watchers Count24
Fork Count94
Commits Count112
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count1
Pull Requests Open Count1
Pull Requests Close Count15
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

jhipsterSampleApplicationReact

This application was generated using JHipster 6.7.1, you can find documentation and help at https://www.jhipster.tech/documentation-archive/v6.7.1.

Development

Before you can build this project, you must install and configure the following dependencies on your machine:

  1. Node.js: We use Node to run a development web server and build the project.
    Depending on your system, you can install Node either from source or as a pre-packaged bundle.

After installing Node, you should be able to run the following command to install development tools.
You will only need to run this command when dependencies change in package.json.

npm install

We use npm scripts and Webpack as our build system.

Run the following commands in two separate terminals to create a blissful development experience where your browser
auto-refreshes when files change on your hard drive.

./mvnw
npm start

Npm is also used to manage CSS and JavaScript dependencies used in this application. You can upgrade dependencies by
specifying a newer version in package.json. You can also run npm update and npm install to manage dependencies.
Add the help flag on any command to see how you can use it. For example, npm help update.

The npm run command will list all of the scripts available to run for this project.

PWA Support

JHipster ships with PWA (Progressive Web App) support, and it's turned off by default. One of the main components of a PWA is a service worker.

The service worker initialization code is commented out by default. To enable it, uncomment the following code in src/main/webapp/index.html:

<script>
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('./service-worker.js').then(function() {
      console.log('Service Worker Registered');
    });
  }
</script>

Note: Workbox powers JHipster's service worker. It dynamically generates the service-worker.js file.

Managing dependencies

For example, to add Leaflet library as a runtime dependency of your application, you would run following command:

npm install --save --save-exact leaflet

To benefit from TypeScript type definitions from DefinitelyTyped repository in development, you would run following command:

npm install --save-dev --save-exact @types/leaflet

Then you would import the JS and CSS files specified in library's installation instructions so that Webpack knows about them:
Note: There are still a few other things remaining to do for Leaflet that we won't detail here.

For further instructions on how to develop with JHipster, have a look at Using JHipster in development.

Building for production

Packaging as jar

To build the final jar and optimize the jhipsterSampleApplicationReact application for production, run:

./mvnw -Pprod clean verify

This will concatenate and minify the client CSS and JavaScript files. It will also modify index.html so it references these new files.
To ensure everything worked, run:

java -jar target/*.jar

Then navigate to http://localhost:8080 in your browser.

Refer to Using JHipster in production for more details.

Packaging as war

To package your application as a war in order to deploy it to an application server, run:

./mvnw -Pprod,war clean verify

Testing

To launch your application's tests, run:

./mvnw verify

Client tests

Unit tests are run by Jest and written with Jasmine. They're located in src/test/javascript/ and can be run with:

npm test

For more information, refer to the Running tests page.

Code quality

Sonar is used to analyse code quality. You can start a local Sonar server (accessible on http://localhost:9001) with:

docker-compose -f src/main/docker/sonar.yml up -d

You can run a Sonar analysis with using the sonar-scanner or by using the maven plugin.

Then, run a Sonar analysis:

./mvnw -Pprod clean verify sonar:sonar

If you need to re-run the Sonar phase, please be sure to specify at least the initialize phase since Sonar properties are loaded from the sonar-project.properties file.

./mvnw initialize sonar:sonar

or

For more information, refer to the Code quality page.

Using Docker to simplify development (optional)

You can use Docker to improve your JHipster development experience. A number of docker-compose configuration are available in the src/main/docker folder to launch required third party services.

For example, to start a mysql database in a docker container, run:

docker-compose -f src/main/docker/mysql.yml up -d

To stop it and remove the container, run:

docker-compose -f src/main/docker/mysql.yml down

You can also fully dockerize your application and all the services that it depends on.
To achieve this, first build a docker image of your app by running:

./mvnw -Pprod verify jib:dockerBuild

Then run:

docker-compose -f src/main/docker/app.yml up -d

For more information refer to Using Docker and Docker-Compose, this page also contains information on the docker-compose sub-generator (jhipster docker-compose), which is able to generate docker configurations for one or several JHipster applications.

Continuous Integration (optional)

To configure CI for your project, run the ci-cd sub-generator (jhipster ci-cd), this will let you generate configuration files for a number of Continuous Integration systems. Consult the Setting up Continuous Integration page for more information.

To the top