rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

setting global PLAYGROUND variable to an empty object in commonJS build script #37

Closed mattahj closed 8 years ago

mattahj commented 8 years ago

When loading playground using webpack I was seeing the following error: playground.js:499 Uncaught TypeError: Cannot set property 'MOBILE' of undefined. I had a look at the source and it seems like it was because of this part:

window.PLAYGROUND = {};

PLAYGROUND.MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

When loaded by webpack, window.PLAYGROUND !== the global PLAYGROUND variable added by the build script, so I updated the build script to initialise PLAYGROUND to an empty object and it seems to work fine with webpack now :)

rezoner commented 8 years ago

I know nothing about webpack so I am trustfully merging this request.

Thanks for your work :+1:

karneaud commented 7 years ago

When loading through webpack I get the following error

Uncaught ReferenceError: PLAYGROUND is not defined at Object._typeof (playground.js:443) at webpack_require__ (bootstrap 5076f24…:19) at Object._typeof (Main.js:2) at webpack_require (bootstrap 5076f24…:19) at Object. (main.min.js:14495) at webpack_require_ (bootstrap 5076f24…:19) at module.exports.ctor.super (bootstrap 5076f24…:65) at bootstrap 5076f24…:65

Looking at line 433


window.ease = ease;

})();

/* file: src/Playground.js */

PLAYGROUND = {};

function playground(args) {

  return new PLAYGROUND.Application(args);

};

I'm new to ES6 but should it have a var?

rezoner commented 7 years ago

Is there a chance you are using some old build?

https://github.com/rezoner/playground/blob/master/build/playground.js#L492

karneaud commented 7 years ago

In my package.json i'm using

...
dependencies: {
"playground.js":"*",
....

So I'm guessing someone needs to update it?

I got it to work eventually by installing babel use-strict disable plugin