问题描述:

The first file that I am passing to uglifyjs declares some namespaces like

window.MyNamespace = {}

when uglifyjs sees this line it complains that window is not defined.

Is there a way to have uglifyjs ignore undefined symbols? I have tried using the --no-dead-code option

网友答案:

You can wrap your global code in a function:

(function(window) {
  window.whatever = something;
  // ...
})(this);

You can also do this:

(function(window) {
  "use strict";

  // ...

})(this);

which is probably a good idea anyway. You'll get warnings/errors from stray undefined variables even without uglify.

相关阅读:
Top