JavaScript minification workflow with Maven

[亡魂溺海] 提交于 2019-12-07 11:40:55

问题


I am wondering about any "best practices" to integrate a "modern JavaScript build workflow" into a Maven build that produces a WAR artifact.

I have found several maven plugins that handle concatenation and minification:

  • WRO4J: https://code.google.com/p/wro4j/wiki/MavenPlugin
  • Minify Maven Plugin: https://github.com/samaxes/minify-maven-plugin
  • YUI: http://alchim.sourceforge.net/yuicompressor-maven-plugin/

However I am still missing how they fit into a full build workflow, since I think it is mandatory to be able to switch concatenation/minification on and off:

For development I want to build a WAR that does not contain the concatenated/minified resources so that I can conveniently debug. For a production build I want to produce a WAR that contains the concatenated/minified resources.

Additionally for the production build I then have to "rewrite" the script URLs in my html to point to the concatenate/minified version(s) of the script(s).

In the JavaScript world I would use Grunt with different grunt tasks (uglify, usemin) to achieve the above workflow. How can I achieve the same in a Maven build?


回答1:


Since you mentioned Grunt, have you considered calling Grunt tasks directly from your Maven build? It's not a perfect solution, but it gives you some more options without relying on Maven plugins. http://addyosmani.com/blog/making-maven-grunt/

Also, this SO topic: Javascript web app and Java server, build all in Maven or use Grunt for web app?




回答2:


You should be able to run maven with different profiles so you can minify js scripts for a production build but build it locally with a different profile for the purposes of debugging.

There's more information about this on Maven's build profile page

Hope this helps.



来源:https://stackoverflow.com/questions/18553292/javascript-minification-workflow-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!