简体   繁体   English

在战争中打包javascript应用(使用grunt和browserify)

[英]package javascript app (that uses grunt & browserify) in war

I have a project that consists of a javascript client app and a maven+spring based REST web service. 我有一个项目,该项目由javascript客户端应用和基于maven + spring的REST Web服务组成。

The javascript app is built using browserify and grunt. javascript应用是使用browserify和grunt构建的。 For this reason I am unable to simply place the html/js source in the src/main/webapp directory of my maven based web service project. 因此,我无法简单地将html / js源代码放置在基于Maven的Web服务项目的src / main / webapp目录中。 What really needs to end up in there is the contents of the javascript app's dist directory after browserify/grunt compilation. 最终需要真正完成的工作是在完成browserify / grunt编译后,javascript应用程序的dist目录中的内容。

Question is: how can I set things up so that the javascript app is packaged w/ the web service war (note that this will need to include the grunt/browserify build steps)? 问题是:我该如何进行设置,以使javascript应用与网络服务大战一起打包(请注意,这将需要包括grunt / browserify构建步骤)?

This is possible by using the frontend-maven-plugin for maven. 这可以通过使用Mavenfrontend-maven-plugin来实现。 I use it do these steps during every maven build: 我在每个Maven构建过程中使用以下步骤:

  • Downloading and installing Node.js (if it doesnt exist already) 下载并安装Node.js(如果尚不存在)
  • Update npm packages 更新npm软件包
  • Executing my frontend build (gulp) 执行我的前端构建(gulp)
  • Gulp will compile my SASS and JS to folders specified in plugin Gulp会将我的SASS和JS编译到插件中指定的文件夹中

I can also trigger gulp build by changing files. 我也可以通过更改文件来触发gulp构建。 Part of my POM (should work similar for grunt): 我的POM的一部分 (咕gr声应该类似):

        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>0.0.26</version>
            <configuration>
                <workingDirectory>src/main/frontend</workingDirectory>
                <installDirectory>.</installDirectory>
            </configuration>
            <executions>
                <!-- Config from: https://github.com/eirslett/frontend-maven-plugin -->
                <!-- phase optional for all executions: default phase is "generate-resources" -->
                <!--  disable some of the following executions to improve build speed -->
                <execution>
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <nodeVersion>v4.1.1</nodeVersion>
                        <npmVersion>3.3.3</npmVersion>
                        <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
                        <npmDownloadRoot>http://registry.npmjs.org/npm/-/</npmDownloadRoot>
                    </configuration>
                </execution>
                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <arguments>install</arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>gulp build</id>
                    <goals>
                        <goal>gulp</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <srcdir>src/main/frontend</srcdir>
                        <outputdir>src/main/webapp/resources</outputdir>
                        <arguments>build</arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM