April 2, 2020
Estimated Post Reading Time ~

How to Use jQuery with Grunt

I have recently started working with Grunt, I loathed at first but it has many varied uses and I seem to have started liking it.

I was recently working on a requirement where I had to create an AEM component automatically with dialogs and clientlibs. More on this later, in a later post. While implementing the requirement, I wanted to use Jquery on grunt for some dom manipulation.

Here is how you do it.
var doc = jsdom(grunt.file.read(//path to html file));
var window = doc.parentWindow;
var $ = require(‘jquery’)(window);
var bodyText = $(“body”).html();

So, simple. I was reading Stackoverflow and came across fs.readFile and fs.readSyncFile which are async and sync functions but they were not simply working and hence i had to use grunt.file.read function.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.