lmd icon indicating copy to clipboard operation
lmd copied to clipboard

"pack" option breaks user-made plugins

Open jeron-diovis opened this issue 10 years ago • 4 comments

I've created my own little plugin as described in manual. Tested it and everything worked just fine. Then I've tried to minify my build by enabling "pack" option in config - and got this:

Uncaught ReferenceError: sandbox is not defined

After some meditation on minified code I made sure that error is exactly in my plugin.

And reason is very simple: after minification sandbox parameter from plugin's IIFE just disappears. So plugin looks like this:

(function (sandbox) { /* some code*/}( /* and nothing here! */));

It is quite unexpected. What have I to do? And why LMD built-in plugins have no such problems?

jeron-diovis avatar Jul 28 '14 11:07 jeron-diovis

Hm, interesting. Please disable flag pack and enable optimize: true. Then send me that block of code again.

azproduction avatar Jul 28 '14 13:07 azproduction

Same result. Code is not uglified now, but parameter for IIFE is still absent. And, maybe I was a bit inattentive - not only last parameter disappears, but it is only gone from function declaration. That is, all I have is just (function () { ... }());.

That's my source code:

(function (sandbox) {
  var oldLmdRequire = lmd_require;
  lmd_require = function(moduleName) {
    var module = oldLmdRequire.apply(this, arguments);
    if (module === undefined)  throw new Error("Module '" + moduleName + "' is undefined!";);
    return module;
  };
  for (var prop in oldLmdRequire) lmd_require[prop] = oldLmdRequire[prop];

  sandbox.require = lmd_require;
}(sandbox));

jeron-diovis avatar Jul 28 '14 14:07 jeron-diovis

Well, please replace (function (sandbox) { with (function (sb) {. It should help. I'll fix this issue as soon as I can.

azproduction avatar Jul 28 '14 15:07 azproduction

Unfortunately, it didn't help. Even more interesting - I've tried several different names instead of "sandbox", and with "sbx" I've got following:

TypeError: Cannot call method 'toString' of undefined
  at Array.make_name ( ... /node_modules/grunt-lmd/node_modules/lmd/node_modules/uglify-js/lib/process.js:1519:21)
  at walk (... /node_modules/grunt-lmd/node_modules/lmd/node_modules/uglify-js/lib/process.js:223:31)
... and so on, very long stack trace ...

It's like some kind of "cumulative" effect. Because when I change parameter name to another one, or even remove some random files from project (with still "sbx" parameter name), there is no such error. It's something really complex.

So I'd rather wait for your fix.

jeron-diovis avatar Jul 28 '14 16:07 jeron-diovis