Minifying JS during Development - Moodle 3.3+

Minifying JS during Development - Moodle 3.3+

by Dave Emsley -
Number of replies: 5
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: -
In reply to Dave Emsley

Re: Minifying JS during Development - Moodle 3.3+

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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)
In reply to Davo Smith

Re: Minifying JS during Development - Moodle 3.3+

by Dave Emsley -

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


In reply to Dave Emsley

Re: Minifying JS during Development - Moodle 3.3+

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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)
In reply to Davo Smith

Re: Minifying JS during Development - Moodle 3.3+

by Dave Emsley -

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



In reply to Dave Emsley

Re: Minifying JS during Development - Moodle 3.3+

by Paul Holden -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

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)