问题
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