I’m getting insanely large bundle sizes, like over 20MB dev, and 10MB prod. The project uses es6 modules, so tree shaking should eliminate unused code, but there’s over 8MB of orphan modules. TBH, even without them we’re looking at over 1.5MB, but at this point I’m willing to live with that.
I based my setup off https://github.com/RaananW/babylonjs-webpack-es6
, which produces 647KB bundles… What did I mess up?
> webpack --config webpack.prod.js
asset all.js 9.68 MiB [emitted] [minimized] [big] (name: main) 1 related asset
asset index.html 147 bytes [compared for emit]
orphan modules 8.01 MiB [orphan] 1058 modules
runtime modules 1.17 KiB 6 modules
cacheable modules 20.7 MiB
modules by path ./node_modules/@babylonjs/core/ 10.1 MiB 305 modules
package.json
"dependencies": {
"@babylonjs/core": "^5.9.0",
"@babylonjs/gui": "^5.9.0",
"@babylonjs/inspector": "^5.9.0",
"earcut": "^2.2.3"
}
tsconfig.json
"target": "es2016",
"module": "es6",
"moduleResolution": "node",
"skipLibCheck": true
webpack.common.js
const path = require("path");
const fs = require("fs");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const appDirectory = fs.realpathSync(process.cwd());
module.exports = {
entry: path.resolve(appDirectory, "src/index.ts"), //path to the main .ts file
output: {
filename: "all.js", //name for the javascript file that is created/compiled in memory
path: path.resolve(__dirname, 'dist'),
clean: true
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(png|jpg|jpeg|gif)/,
use: ["image-loader"]
}
],
},
plugins: [
new HtmlWebpackPlugin({template: 'www/index.html'})
]
};
webpack.prod.js
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js')
module.exports = merge(common, {
mode: 'production'
});