Gruntfile.js in custom theme vs moodle folder

Gruntfile.js in custom theme vs moodle folder

by Rosa GF -
Number of replies: 6

Hello

I've being studying theming in Moodle and I found that some themes save the Gruntfile.js in the theme folder with their configuration. I have installed grunt following the instrucctions in the Moodle root. In the case that I install that custom theme, do I have install grunt in its folder? I have searched, but I was unable to find about it.

Thanks a lot for any help smile

Average of ratings: -
In reply to Rosa GF

Re: Gruntfile.js in custom theme vs moodle folder

by Mary Evans -

Hi Rosa,

If you are using grunt while making the theme, then you need the grunt and json files. But after the theme is made it should not need any extra grunt manipulation by the user as most would not know how to go about doing all that needs to be done before you even attempt to change any elements in those files.

But that is just my own personal view.

Cheers

Mary

Average of ratings: Useful (1)
In reply to Rosa GF

Re: Gruntfile.js in custom theme vs moodle folder

by David Scotson -

Grunt gets installed in two parts, one called grunt-cli that is installed with something like "npm install -g grunt-cli", the -g means global so it can be used anywhere on your system and doesn't need to be installed multiple times.


Then you need to run "npm install" in the directory to set up the Gruntfile. That needs to be done once for core moodle, and once for each theme that you're working on.


Running grunt in  a directory will search for a Gruntfile, working it's way up the directory structure, stopping at the first one it finds.

Now that core ships a grunt file, the themes that use grunt should probably alter their gruntfiles to pass on any commands they don't understand to the core Gruntfile. I think currently it'll mean that the core grunt commands will fail if you try to run them inside a theme directory. My colleague has done this, I'll ask him to post details here.



Average of ratings: Useful (2)
In reply to David Scotson

Re: Gruntfile.js in custom theme vs moodle folder

by Rosa GF -
Thanks very much smile

I thought that leaving the Gruntfile.js in the theme folder will help themers when they subtheme. But I wanted to make it well and didn't know how to find the documentation, though I searched smile

Have a good day smile
In reply to David Scotson

Re: Gruntfile.js in custom theme vs moodle folder

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Thanks David, that helped me too. I was looking for a way to use Grunt to compile my plugin's styles.css file from my custom .less file. I was using recess for that in the past but that stopped working (as is announced at https://github.com/twitter/recess).

I have documented my way at https://docs.moodle.org/dev/Grunt#Using_Grunt_in_additional_plugins - please feel free to review, correct and/or expand that. Thanks again.

In reply to Rosa GF

Re: Gruntfile.js in custom theme vs moodle folder

by Guy Thomas -
Picture of Core developers Picture of Plugin developers

You can sometimes run in to trouble if you have a Gruntfile.js in a theme's folder if you want to compile an AMD module within that theme.


We had to modify our theme's Gruntfile.js and package.json to make it include the core grunt tasks in our Gruntfile.js


Modification to package.json:

    "grunt-load-gruntfile" : "^0.0.2" <- added to "devDependencies"


Modification to the themes Gruntfile.js module exports


module.exports = function(grunt) {


    // We need to include the core Moodle grunt file too, otherwise we can't run tasks like "amd".

    require("grunt-load-gruntfile")(grunt);

    grunt.loadGruntfile("../../Gruntfile.js");


Modification to the themes Gruntfile.js  grunt.initConfig (note grunt.initConfig is swapped for grunt.mergeConfig)


    grunt.mergeConfig = grunt.config.merge;

    grunt.mergeConfig({