thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
934 stars 87 forks source link

Shim modules that use undeclared variables in the global scope #220

Closed mikehaertl closed 7 years ago

mikehaertl commented 7 years ago

I try to transform a "module" that defines a variable in the global scope without var:

yii = (function ($) {
    var pub = {
    }
    return pub;
})(jQuery);

Unfortunately this does not work. When I import this into my project I end up with a Uncaught ReferenceError: yii is not defined in the browser, obviously because this code is not strict, and you can not mix strict + non-strict code in a single file.

So I wonder is this supposed to work? And if not, can this be implemented in browserify-shim or am i completely out of luck here?

Here's the relevant part from my package.json:

 "devDependencies": {
    ...
    "browserify-shim": "^3.8.12",
  },
  "browserify": {
    "transform": [
      "browserify-shim",
      ["babelify", {
        "presets": "es2015"
      }]
    ]
  },
  "browserify-shim": {
    "../../vendor/yiisoft/yii2/assets/yii.js": "yii"
  },
  "scripts": {
    "js:browserify": "browserify -d scripts/main.js > main.js && touch main.js.map",
  }
bendrucker commented 7 years ago

Hi, sorry this didn't get a response. At the moment browserify shim doesn't get around the strict mode violation you've described.