Jump to content

BabylonJS + Webpack


mop
 Share

Recommended Posts

Hi,

 

I just switched to webpack in one of my babylon.js projects and found a few oddities:

 

1. src version as "main" in package.json

 

This is not only webpack related. As far as I am aware libraries should not refer to a minimized version here. Browserify, webpack and the likes will do minification if desired. I couldn't find the package.json in the git repository. Would have created a pull request but it doesn't seem to be there :o

 

2. "use strict";

 

As my project is ES2015 I am using babel to transpile it back to es5. During this process babel will prepend a "use strict" to every script (for whatever reason ;) ). I am cloning a few meshes in my project and I think it found a possible bug there:

 

Uncaught (in promise) TypeError: Cannot set property hasLODLevels of #<r> which has only a getter
    at Function.r.DeepCopy (http://localhost:8080/output.js:20748:93937)
 
The problem here is that DeepCopy will iterate over all properties and copy the value to the cloned mesh. This includes all the properties defined via Object.defineProperty :o However they are getters only and thus it throws an error here. That makes perfect sense. Maybe babylon.js should always include "use strict"?  Maybe there are more potential bugs hiding out there ;)
 
Currently I am just ignoring babylon.js while building.
Link to comment
Share on other sites

Hey mop, I've just been moving my project to webpack as well. Really powerful, although some of the configuration is really hairy.

 

About 1. package.json - right now Babylon.js is not set up to be required as a module. So even if there was a package.json and it specified an entry point, webpack (or alternatives like browserify) wouldn't be able to resolve it as a dependency.

 

What you can do is get webpack to consider a pre-made babylon file as a (static) dependency of your project, so that it gets copied into the distribution (and handled by webpack-dev-server). I'm doing this with the file-loader module. For example, if you put a minified babylon file in /external/ , you could then add this anywhere in your javascript:

require('file?name=b.js!./external/babylon.2.3.min.js'); 

and change your html to reference the script from webpack:

<script type="text/javascript" src="b.js"><script> 

This way webpack will treat babylon as a dependency, but not parse it for dependencies or minifiy it or add strict markers and so forth (which is realistically for the best).

Link to comment
Share on other sites

Hey mop, I've just been moving my project to webpack as well. Really powerful, although some of the configuration is really hairy.

 

About 1. package.json - right now Babylon.js is not set up to be required as a module. So even if there was a package.json and it specified an entry point, webpack (or alternatives like browserify) wouldn't be able to resolve it as a dependency.

 

What you can do is get webpack to consider a pre-made babylon file as a (static) dependency of your project, so that it gets copied into the distribution (and handled by webpack-dev-server). I'm doing this with the file-loader module. For example, if you put a minified babylon file in /external/ , you could then add this anywhere in your javascript:

require('file?name=b.js!./external/babylon.2.3.min.js'); 

and change your html to reference the script from webpack:

<script type="text/javascript" src="b.js"><script> 

This way webpack will treat babylon as a dependency, but not parse it for dependencies or minifiy it or add strict markers and so forth (which is realistically for the best).

 

Hi fenomas!

 

I didn't know about this as well but actually there is a proper babylonjs package on npm which properly exports BABYLON as a module:

 

https://www.npmjs.com/package/babylonjs

 

The only thing I currently do to work around the strict bug is to ignore babylonjs in my .babelrc like so:

 

{
    "ignore": "node_modules/babylonjs/*",
    "presets": [
        "react",
        "es2015",
    ]
}
 
However I can perfectly do
 
import BABYLON from "babylonjs";
 
now :)
 
So in my setup I have a pretty bare webpack config without any specialties :)
Link to comment
Share on other sites

Ahh! Okay, that'll work too.

 

It's good to know about the npm module. I use a script to pull in dailies from github, because quite often I'll complain about something here and DK will have it fixed a few hours later. ;) 

 

In any case I imagine the module on npm is probably built from Tools/Gulp, with the package.json in that folder. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...