Quantcast
Channel: Bugs Latest Topics
Viewing all articles
Browse latest Browse all 760

[2.5.0-beta] After Canvas2D move BABYLON is undefined

$
0
0

Hi,

I am unsure if this is a bug or incompatible with my setup, but I run the latest nightly build of Babylon.js 2.5.0-beta commit 3fe3372 using a repository I set up that fetches the latest preview build and allows me to install it through npm as a package. I am then using Webpack together with Typescript to import the library. I understand that this might not be the standard workflow, but it has been running smoothly for me until the Canvas2D refactoring. So down to the issue:

In a simple Javascript setup such as this using webpack for requires, CANVAS2D will fail to run due to the fact that BABYLON is undefined.

const BABYLON = require('babylonjs');
const CANVAS2D = require('babylonjs/babylon.canvas2d');
new CANVAS2D.Rectangle2D({})

First I thought it was that my requires were messed up, which turned out to be half true. Webpack had to provide the CANVAS2D module with the BABYLON module, by making the BABYLON module globally available.

new webpack.ProvidePlugin({
  BABYLON: 'babylonjs',
}),

However this wasn't the entire issue, due to the fact that the CANVAS2D module is also defined as BABYLON and the first lines of the code overwrite the globally available BABYLON variable with it's own declaration of BABYLON.

var BABYLON;
(function (BABYLON) {
  // ...
})(BABYLON || (BABYLON = {}));

Removing all var BABYLON; in the compiled code fixed my issues, but maybe it might be worth giving Canvas2D its own CANVAS2D module/namespace, if they are now to be treated as separate modules in the repository.

Regards

Swiftwork


Viewing all articles
Browse latest Browse all 760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>