Unable to build javascript files with grunt

Unable to build javascript files with grunt

by Conn Warwicker -
Number of replies: 3
Picture of Core developers Picture of Plugin developers

When I go into my plugin directory and run `grunt amd --force` to try and build the files, I get tonnes of errors.

Firstly, it seems to do all the installed plugins and themes, not just the actual plugin I'm ideveloping at the moment, though that doesn't matter that much.

Across all the plugins, I get thousands of errors about trailing spaces or, linebreaks being 'CRLF' instead of 'LF', etc... and the "eslint:amd" task then fails.

Then when it gets onto the "uglify:amd" task, I get a specific error in one of my plugins:

    Warning: Uglification failed.

    SyntaxError: Unexpected token: name (url).

    Line 59 in blocks/elbp/amd/src/scripts.js

Which points to this:

    let url = ELBP.www + "/blocks/elbp/js/ajaxHandler.php";


I googled the error and on the github it suggests that this uglify does not support ES6 and I'd need to use some other branch of grunt or something. I've just been following the instructions in the Moodle documentation.

Has anyone else come across this in their development? How did you get around it? Do I have to use grunt, or is it just a suggestion?


Thanks

Average of ratings: -
In reply to Conn Warwicker

Re: Unable to build javascript files with grunt

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If it's lack of ES6 support, do you just need to do var instead of let?

In reply to Conn Warwicker

Re: Unable to build javascript files with grunt

by Bas Brands -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers
Hi Conn,

When you cd into your plugins amd folder: "cd blocks/yourblockname/amd" you should be able to run "Grunt amd" and it should only compile the the src/*.js in your plugin.
In reply to Bas Brands

Re: Unable to build javascript files with grunt

by Conn Warwicker -
Picture of Core developers Picture of Plugin developers
That's what I've been doing, but it runs all the plugins anyway.