Build Hooks on Oracle JET

Jason Scarfe
Oracle Developers
Published in
2 min readSep 1, 2017

The reason I love JET is because of the stuff we get for free with it. Part of this free stuff includes the build tools which are seriously undersold in my opinion.

Oracle JET Data Visualization Components

So when I started to look into how I could hook in a ‘post-process’ event say, for example, uglifying and compressing my override.css I got a little confused.

I started going down the wrong track of trying to tie into the command we use to release (the serve command). I was doing this as I wanted all the good uglifying, compressing stuff JET comes with plus my custom action at the end.

Now the issue comes if you try and extend the serve command. You cannot do this as the serve action never finishes because its busy hosting your site!

So the obvious thing I missed is that the build option actually does all the good uglyfing, compressing stuff as well and it doesnt try to serve your app.

This means I can finally hook into JET build tool properly and compress my override.css after JET has finished building.

How do you do this? Simple:

Edit the Gruntfile.js that comes with your scaffolded app and register a new task:

grunt.registerTask("cm-build","build for chef market", function (buildType) {

console.info("running Jasons super duper release task")
if (buildType == "release" ){
//do some cool stuff here for a normal build
} else {
//do some cool stuff here for a normal build
})

and make sure we call the new task within the already, predefined grunt run:

grunt.task.run([`oraclejet-build:${buildType}`,`cm-build:${buildType}`]);

Note that my cm-build task takes in buildType — we use this for determining if release was passed in. This brings us nicely on how we run this task:

grunt build:release

buildType is set to release or if we do a vanilla, plain grunt build it is undefined. This means that within our task we can determine if its a release build or not.

So, the takeaway here is: You can use the build for releasing; you do not have to rely on the serve!

— Jason Scarfe :: Griffiths Waite

--

--