AMD src and build files

AMD src and build files

Matti Jordman -
Erantzun kopurua: 4

Hi

I've javascript files of my module in amd/src folder and after grunt in amd/build folder. For example:

amd/src/main.js
amd/build/main.min.js

view.php calls:
$PAGE->requires->js_call_amd('mod_mymodule/main', 'Init')

It looks like main.js and other src files are always loaded. How do I get main.min.js and other min files loaded? Should or can I remove src files (causes an error)? Should I change the js_call or something else?

Thanks

Puntuazioen batez bestekoa: -
Matti Jordman(e)ri erantzunda

Re: AMD src and build files

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia

Whether the source files or build files are used depends on an admin settings whose name I forget. The point is that when you are doing development, you want it to use the src file, so you can just edit the file and reload to test, and also use the JavaScript debugger on readable code. Then, your real Moodle site, where performance is important, will use the minified file.

So, anyway, don't be surprised if it uses the non-minified files during development. This is a feature.

Puntuazioen batez bestekoa:Useful (1)
Tim Hunt(e)ri erantzunda

Re: AMD src and build files

Andreas Grabs -
Core developers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia Translators-ren irudia

Hi,

the settings has to be made in "config.php":

$CFG->cachejs = false;

With this the "src" files are used.

Best regards
Andreas

Puntuazioen batez bestekoa:Useful (1)
Andreas Grabs(e)ri erantzunda

Re: AMD src and build files

Davo Smith -
Core developers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia

As long as you have debugging set to 'developer', you will get the non-minified files served, if you switch off debugging, then the minified files are served instead. I can't verify the cachejs setting, as I've never used it myself (I guess it is irrelevant if you've already got debugging on).

One other helpful setting is $CFG->jsrev = -1; as that means you can just refresh the browser to get the latest javascript, without having to purge the site caches (at least, as far as I know - it still seems to work whenever I try it, I've not actually hunted through the code to confirm it).