The Grails war command will copy the resources for the war file into a staging directory. Before the war file is built, we will get a “CreateWarStart” event which gets the war name and the staging directory. This is where we can call the optimizer command. Following is an example that can be placed in our _Events.groovy script. It assumes you’ve placed the Rhino js.jar and the Require.JS r.js optimizer script in the Scripts folder.
The final step is to update our GSP file so it uses the -build version of the main script. Following is an example of the script line adds -build if we are running in a war