Minify help please

For developers using the Construct 2 Javascript SDK

Post » Tue Oct 11, 2016 11:39 pm

Hi. I am creating a plugin for c2 but I'm stumbling over how to make it minify-proof. The library that I am using has one line that breaks the dot syntax rule as described here (I think) and I am a little over my amateur-coding head. The function looks like this:

Code: Select all
if (typeof exports !== 'undefined')
{ if (typeof module !== 'undefined' && module.exports)
  { exports = module.exports = newObjFn({}) }
  else { exports.LibraryName= newObjFn({}) }
} else {
  if (typeof define === 'function' && define.amd)
  { define( 'LibraryName',[],function(){return newObjFn({})} ) }
  else //
  { (1,eval)('this').LibraryName= newObjFn({}) }


The last 2 lines need to be fixed (dot syntax is used throughout the rest of the plugin AFAIK). Can anyone help please? How can I re-write those last 2 lines so that functionality is retained whilst dot syntax is used instead?

Thanks.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Wed Oct 12, 2016 3:06 am

Does the plugin cease to work if you minify as it is now? If your plugin is the only js that accesses the library, and you included the library as a dependency then I'd think there was no reason to change anything in the library.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Wed Oct 12, 2016 9:12 am

@R0johound - thanks for your help. It got me thinking and I did a bit more investigation - I was surprised that the attached library wasn't minified by the export process (is this correct?). When I saw that I realised that the problem was caused by my using dot operators in the runtime.js on functions that required their names to be maintained to access the library. It's all looking good now and as soon as I have a good demo going I'll post the plugin in the other forum. Cheers :).
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests