2

我目前正在使用 AngularJs 为嵌入式服务器(打包在 .jar 文件中,作为 Tomcat 运行)开发前端/webapp。服务器有一些我希望能够在前端使用的 API 端点。

我目前的方法是使用 webjars 加载我选择的 angularjs 版本,然后在 webapp 文件夹中构建应用程序。结构是这样的:

├───src
│   ├───main
│   │   ├───docker
│   │   ├───java
│   │   │   └───com
│   │   │       └───...    
│   │   ├───resources
│   │   └───webapp
│   │       └───public
│   │           ├───css
│   │           └───js
│   │               └───controllers
└───target
    ├───classes
    │   ├───com
    │   │   └───... 
    │   └───public
    │       ├───css
    │       └───js
    │           └───controllers
    ├───generated-sources
    │   └───annotations
    ├───generated-test-sources
    │   └───test-annotations
    └───test-classes
        └───com
            └───...

我正在编辑的文件位于 src/main/webapp/public 文件夹中,它们正在“编译”到 target/classes/public 文件夹中。如果我想在服务器运行时重新加载文件,我必须执行Run -> Reload Changed Classes,这在开发时工作得很好。

但由于我最初来自“独立”AngularJs 开发,因此我习惯于拥有真正的 livereload 和构建链,该构建链会缩小和连接 js/css 文件以进行优化(grunt,bower)。

现在我已经研究了 wro4j 并且能够很好地设置它。对我来说仍然缺少的一件事是热重装。甚至上述方法也不再适用于 wro4j,因此唯一的选择是重新编译整个应用程序以查看 css/javascript 或 HTML 内部的变化。有没有简单的方法解决这个问题?

我的首选方法是在开发时处理未缩小/未连接的版本(在调试中运行服务器),并且仅在部署应用程序(或仅运行)时执行整个构建链

我有哪些选择?

4

2 回答 2

1

在http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html查看 Spring Boot DevTools 文档

马文。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

摇篮。

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

它包括一个内置的 LiveReload 服务器。您应该能够通过运行“Make Project”从 IntelliJ 更新您的应用程序。

于 2016-09-25T13:47:19.753 回答
0

我最终做的可能有点矫枉过正,但我​​没有找到任何其他合适的解决方案。

我构建了一个 Gruntfile.js(基于 angularjs 的 yeoman 生成器),以便能够拥有 livereload 和 build-chain 功能(concat、minify 等)。有了这个,我也能够在前端工作,而不必启动服务器。该文件中唯一的“肮脏黑客”是将grunt build其 dist 文件夹复制到该/src/main/resources/static文件夹​​,以便将其“编译”到 .war 文件中。

我使用了一些 maven 插件以便能够在构建时执行所需的命令(npm install、bower install、grunt build、grunt clean)

<plugin>
 <groupId>com.github.eirslett</groupId>
 <artifactId>frontend-maven-plugin</artifactId>
 <version>0.0.22</version> <!-- last version supported by maven 2 -->
 <dependencies>
     <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-utils</artifactId>
         <version>2.1</version>
     </dependency>
 </dependencies>
 <configuration>
     <nodeVersion>v0.10.18</nodeVersion>
     <npmVersion>1.3.8</npmVersion>
     <workingDirectory>src/main/frontend</workingDirectory>
 </configuration>
 <executions>
     <execution>
         <id>install node and npm</id>
         <goals>
             <goal>install-node-and-npm</goal>
         </goals>
         <phase>generate-resources</phase>
     </execution>
     <execution>
         <id>npm install</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>bower install</id>
         <goals>
             <goal>bower</goal>
         </goals>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>npm rebuild</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <configuration>
             <arguments>rebuild node-sass</arguments>
         </configuration>
     </execution>
     <execution>
         <id>grunt build</id>
         <goals>
             <goal>grunt</goal>
         </goals>

         <configuration>
             <arguments>build</arguments>
         </configuration>
     </execution>
     <execution>
         <id>npm install before clean</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <phase>clean</phase>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>grunt clean</id>
         <goals>
             <goal>grunt</goal>
         </goals>

         <phase>clean</phase>

         <configuration>
             <arguments>clean</arguments>
         </configuration>
     </execution>
 </executions>
</plugin>

我希望这为我的方法提供了一个广泛的想法。这当然不是完美的,特别是因为它增加了整个项目的构建时间。

于 2016-11-25T21:48:31.590 回答