Jump to content

Using webpack to bundle babylon, and using typescript


Nikos123
 Share

Recommended Posts

I'm working on an RTS game called density wars, but am not sure how to include babylon in my build.

 

In my main game file I do this, and babyon is present in my code

require('babylonjs');class Game {numCores:number;defaultY:number;

but when I go to use it, babylon is undefined:

constructor() {var self = this;this.numCores = 6;this.defaultY = 1;// Load BABYLON 3D enginethis.canvas = <HTMLCanvasElement> document.getElementById("glcanvas");this.engine = new BABYLON.Engine(this.canvas, true);this.scene = new BABYLON.Scene(this.engine);

config:

module.exports = {context: __dirname + "/lib",entry: {main: ["./game.ts"]},output: {path: __dirname + "/dist",filename: "density-wars.js"},devtool: "source-map",module: {loaders: [{test: /\.ts$/,loader: 'awesome-typescript-loader'},{ test: /\.css$/, loader: "style-loader!css-loader" }]},resolve: {// you can now require('file') instead of require('file.js')extensions: ['', '.js', '.json']}}
Link to comment
Share on other sites

If I do this:

/// <reference path="../babylonjs.d.ts" />require('../style.css');import BABYLON = require('babylonjs');class Game {

I now get an error:

 

ERROR in /Users/me/WebstormProjects/Density-Wars/lib/game.ts:10:25 
File '/Users/me/WebstormProjects/Density-Wars/babylonjs.d.ts' is not a module.
Link to comment
Share on other sites

  • 3 months later...

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...