Hello, I would like to include cannon physics module.
But I beleve I have problem to configuration files this.
I red this Documentation NPM - Babylon.js Documentation
If I understand right. bundle.js (built js code) have problem with CANNON physics module.
WHAT I’M MISSING ??
Can anybody help me solve this problem. I need Help
I do npm build and npm start (it looks ok)
But in build bundle.js code have problem.
When I run http://localhost:8080/. in console I have
problem:
Uncaught ReferenceError: CANNON is not defined
at new e (bundle.js:149)
at Game…/src/Game.ts.Game.test (bundle.js:10643)
at bundle.js:10826
MY CODE IS in ts class have problem here:
-> let gravityVector = new BABYLON.Vector3(0, -5, 0);
-> let physicsPlugin = new BABYLON.CannonJSPlugin();
MY CONFIGURATION FILES ARE
---------- package.json ----------
{
“name”: “tswebpack4”,
“version”: “1.0.0”,
“description”: “https://appdividend.com/2018/03/18/how-to-setup-typescript-with-webpack-4/”,
“main”: “index.js”,
“dependencies”: {
"babylonjs": “^4.0.0-beta.3”,
“babylonjs-gui”: “^4.0.0-beta.3”,
“babylonjs-loaders”: “^3.3.0”,
"cannon": “^0.6.2”,
“jquery”: “^3.3.1”,
“pepjs”: “^0.4.3”
},
“devDependencies”: {
“@types/jquery”: “^3.3.29”,
“@types/node”: “^11.12.0”,
“copy-webpack-plugin”: “^5.0.2”,
“css-loader”: “^2.1.1”,
“extract-text-webpack-plugin”: “^3.0.2”,
“file-loader”: “^3.0.1”,
“style-loader”: “^0.23.1”,
“ts-loader”: “^5.3.3”,
“typescript”: “^3.3.4000”,
“url-loader”: “^1.1.2”,
“webpack”: “^4.29.6”,
“webpack-cli”: “^3.3.0”,
“webpack-dev-server”: “^3.2.1”
},
“scripts”: {
“build”: “webpack”,
“start”: “webpack-dev-server --mode development”,
“test”: “echo “Error: no test specified” && exit 1”
},
“keywords”: [],
“author”: “”,
“license”: “ISC”
}
},
“keywords”: [],
“author”: “”,
“license”: “ISC”
}
---------- tsconfig.json ---------
{
“compilerOptions”: {
“outDir”: “./dist/”,
“sourceMap”: true,
“module”: “commonjs”,
“target”: “es5”,
“sourceMap”: true,
“types”: [
“jquery”,
“babylonjs”,
“babylonjs-loaders”,
“babylonjs-gui”
],
},
“exclude”: [
“node_modules”
]
}
--------- webpack.config.js ---------
const webpack = require(‘webpack’);
const path = require(‘path’);
const copy_webpack_plugin = require(‘copy-webpack-plugin’);
module.exports = {
mode: “development”,
entry: ‘./src/index.ts’,
devtool: ‘inline-source-map’,
module: {
rules: [
{
test: /.tsx?/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test:/\.css/,
use:[‘style-loader’,‘css-loader’]
},
{
test: /.(png|jpg|svg)/,
use: [{
loader: 'url-loader',
options: {
limit: 8000,
name: 'images/[hash]-[name].[ext]'
}
}]
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
: ‘jquery’,
jquery: ‘jquery’
}),
new copy_webpack_plugin([
{from:‘src/images’,to:‘images’}
]),
new copy_webpack_plugin([
{from:‘src/styles’,to:‘styles’}
])
,
new copy_webpack_plugin([
{from:‘src/assets’,to:‘assets’}
])
],
externals: {
//oimo: ‘OIMO’, //or true
//cannon: ‘CANNON’ //or true
//“oimo”: true,
"cannon": true
//“earcut”: true
}
};