I have not much experience with this topic yet but just want to give my 5 cents to it:
You may check out this boilerplate setup: GitHub - BeardScript/babylonjs-webpack-boilerplate: BabylonJS + Webpack minimal boilerplate for development and production, supporting es6 and/or typescript.
Just clone it with GIT…
I used this for the start, because webpack is not easy
After an update of all npm modules I needed to change the webpack.config.js like this:
let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let LiveReloadPlugin = require('webpack-livereload-plugin');
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname,'dist'),
filename: 'bundle.js'
},
resolve: {
modules: [path.resolve(__dirname, '/src'), 'node_modules/'],
descriptionFiles: ['package.json'],
extensions : ['.js', '.ts', '.tsx']
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
use: 'ts-loader',
test: /\.tsx?$/,
exclude: /node_modules/
},
{
use: ['style-loader', 'css-loader'],
test: /\.css$/
}
]
},
plugins: [
new HtmlWebpackPlugin({
inject: false, //prevents double firing the code
template: 'index.html'
}),
new LiveReloadPlugin()
],
externals: {
oimo: 'OIMO', //or true
cannon: 'CANNON', //or true
earcut: 'EARCUT'
}
};
/* const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
var CompressionWebpackPlugin = require('compression-webpack-plugin');
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map';
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new UglifyJsPlugin({
sourceMap: true
}),
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|ts|vue|json|png|jpg|gif|svg)$/,
threshold: 10240,
minRatio: 0.8
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.LoaderOptionsPlugin({
minimize: true
})
]);
} */
Needed to comment out the UglifyJsPlugin because it was not working anymore after the update and I don’t had the time yet to go deeper, but it works nice now!
Not excactly answeres your question, but maybe it can help 