I am follwoing the Physics doc but I am not able to inlcude cannonjs keep getting this following error
Uncaught ReferenceError: CANNON is not defined
at new CannonJSPlugin (cannonJSPlugin.js:21:82)
at new App (app.ts:85:27)
at eval (app.ts:299:1)
at ./src/client/app.ts (bundle.js:1:9047386)
at __webpack_require__ (bundle.js:1:26021875)
at bundle.js:1:26034378
at bundle.js:1:26034422
I have followed this CANNON including problem? - #5 by Ian_Sheehan but nothing seems works for me. I am using the latest webpack that doesnât supports externals
also tried import * as CANNON from 'cannon';
/ import * as cannon from 'cannon';
but no luck. last thing I have tried window.CANNON = require('cannon');
in my index.d.ts
file.
my webpack config
`
const path = require(âpathâ);
const fs = require(âfsâ);
const { CleanWebpackPlugin } = require(âclean-webpack-pluginâ);
const HtmlWebpackPlugin = require(âhtml-webpack-pluginâ);
const TerserPlugin = require(âterser-webpack-pluginâ);
const appDirectory = fs.realpathSync(process.cwd());
const babelOptions = {
presets: [
[
â@babel/preset-envâ,
{
targets: {
browsers: [â>0.25%â, ânot ie 11â, ânot op_mini allâ],
},
modules: false,
},
],
],
};
module.exports = {
entry: path.resolve(appDirectory, âsrc/client/app.tsâ), //path to the main .ts file
// mode: âdevelopmentâ, //production
output: {
path: path.resolve(__dirname, âdistâ),
filename: âbundle.jsâ,
},
resolve: {
extensions: [â.tsxâ, â.tsâ, â.jsâ],
},
devServer: {
host: â0.0.0.0â,
port: 8080, //port that weâre using for local host (localhost:8080)
static: path.resolve(appDirectory, âpublicâ), //tells webpack to serve from the public folder
hot: true,
devMiddleware: {
publicPath: â/â,
},
},
module: {
rules: [
// {
// test: /.tsx?$/,
// use: âts-loaderâ,
// exclude: /node_modules/,
// },
{
test: /.ts(x)?$/,
exclude: /node_modules/,
use: [
{
loader: âbabel-loaderâ,
options: babelOptions,
},
{
loader: âts-loaderâ,
},
],
},
{
test: /.css$/,
use: [âstyle-loaderâ, âcss-loaderâ],
},
{
test: /.json$/,
loader: âjson-loaderâ
},
{
test: /.(png|svg|jpg|jpeg|gif)$/i,
type: âasset/inlineâ,
use: [
{
loader: âurl-loaderâ,
options: {
limit: 8192,
},
},
],
},
{
test: [/.vert$/, /.frag$/],
use: âraw-loaderâ,
},
{
test: /.(woff|woff2|eot|ttf|otf)$/i,
type: âasset/resourceâ,
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: true,
output: {
comments: false,
},
},
}),
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(appDirectory, âpublic/index.htmlâ),
}),
],
};
`