thibo73800/metacar

Metacar module should not bind to window object

abaybektursun opened this issue · 0 comments

The dist version of the module metacar.min.js looks like this:

window.metacar=function(t) {

This can be easily solved by changing the libraryTarget in webpack.config.js

var packageConfig = Object.assign({}, config, {
    output: {
        filename: 'metacar.min.js',
        path: path.resolve(__dirname, './dist'),
        library: 'metacar',
        libraryTarget: 'window', 

From libraryTarget: 'window' to libraryTarget: 'commonjs'. Having window object as a target is a problem because for example it is not accessible from Web Workers.

However, there is still another issue: Pixi.js. First of all, it's in externals it really should be bundled with the module. Second of all, Metacar tries to use pixi during the import. Is pixi just used for rendering or is it core part of the game? If it is used just for rendering this problem can be solved be having two separate modes: 1. Simulations 2. Rendering. During the simulation rendering libraries should not be touched. If Pixi lies in the core of the the simulation, you can use jsdom + canvas, node-pixi, or pixi-shim to prevent it from accessing DOM during stimulation. more info: pixijs/pixijs#4771