General developer forum

Minifying JS during Development - Moodle 3.3+

 
Picture of Dave Emsley
Minifying JS during Development - Moodle 3.3+
Particularly helpful Moodlers
Hi all,

I'm developing a theme that uses jQuery I'm having to minify my js and put it into /amd/build every time I make a change; I'm also having to purge the caches.  I'm in theme developer mode. 

Surely I shouldn't have to do this?  what have I missed please?



Cheers

Dave


 
Average of ratings: -
Davo
Re: Minifying JS during Development - Moodle 3.3+
Core developersParticularly helpful MoodlersPlugin developers

Do you have debugging set to 'Developer'?

If that doesn't help, then make sure $CFG->jsrev = -1; is set in your site config.php.

Also, you imply that you are manually minifying + copying your javascript each time - I just wanted to check that you're not just using grunt to do this for you?


 
Average of ratings: Useful (1)
Picture of Dave Emsley
Re: Minifying JS during Development - Moodle 3.3+
Particularly helpful Moodlers

Hi Davo,

Yes, it is set to developer. 

I'll try that in the site config.php thanks.

I'm not using grunt as I wasn't quite sure what it did or how to work it.

Cheers

Dave


 
Average of ratings: -
Davo
Re: Minifying JS during Development - Moodle 3.3+
Core developersParticularly helpful MoodlersPlugin developers

Try reading the docs on it - https://docs.moodle.org/dev/Grunt

You should definitely using that instead of any solution that involves manually minifying + copying files.


 
Average of ratings: Useful (1)
Picture of Dave Emsley
Re: Minifying JS during Development - Moodle 3.3+
Particularly helpful Moodlers

OK I've installed Grunt on the server and it is running "grunt watch".

demsley@orangeServer:/home/learndom/public_html/moodle/theme/curlew$ sudo grunt watch
Running "watch" task
Waiting...

...and I've updated the .js file in theme/curlew/amd/src and pushed it to the server and I get:

>> File "theme/curlew/amd/src/startup.js" changed.
Running "eslint:amd" (eslint) task
/home/learndom/public_html/moodle/theme/curlew/amd/src/startup.js
   1:26  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   2:94  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   3:1   error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   4:37  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   5:1   error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   6:49  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   7:1   error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style
   8:13  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style 
......
  16:56  error  Trailing spaces not allowed                      no-trailing-spaces
✖ 49 problems (49 errors, 0 warnings)

49 errors - not bad in 24 line script  wink

Anyway

Many Thanks Davo and Paul



 
Average of ratings: -
Picture of Paul Holden
Re: Minifying JS during Development - Moodle 3.3+
Core developersParticularly helpful MoodlersPlugin developers

As Davo mentions, you ought to be using Grunt to build your AMD modules - as well as minifying your code, it also does linting, etc.

 
Average of ratings: Useful (1)