define not working with spfx / sharepoint online
usually when we use modern plugins you will see something like this in the top of the JS file:
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SOMEPLUGINNAME=e()}(this,(function(){"use strict"; //more js code
BUT you will see errors like "SOMEPLUGINNAME is not defined", "cannot find module", ect.
the reason is that MS overrides so many things and "define" as well, and i am not sure why it fails.
BUT all that code wants to find the the "Window" object as named above globalThis
So lets help him and change to
!function(t,e){(t="undefined"!=typeof globalThis?globalThis:t||self).SOMEPLUGINNAME=e()}(this,(function(){"use strict"; //more js code
or even just !function(t,e){globalThis.SOMEPLUGINNAME=e()}
BTW for adding all those JS files in the right order:
to be used like this
and "assets" is just a DocLib in my sp-site
Comments
Post a Comment