Guest User

webpack.config.js

a guest
Sep 9th, 2025
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  5.  
  6. module.exports = {
  7.   entry: './src/min-babylon.ts',
  8.   output: {
  9.     filename: 'babylon.custom.min.js',
  10.     path: path.resolve(__dirname, 'scripts'),
  11.     library: 'BABYLON',
  12.     libraryTarget: 'window',
  13.     clean: false,
  14.     chunkFilename: '[id].babylon.custom.min.js'
  15.   },
  16.   mode: 'production',
  17.   target: ['web', 'es2018'],
  18.   devtool: false,
  19.   resolve: {
  20.     extensions: ['.ts', '.js'],
  21.     mainFields: ['module', 'browser', 'main'],
  22.     fallback: {}
  23.   },
  24.   module: {
  25.     rules: [
  26.       {
  27.         test: /\.ts$/,
  28.         use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
  29.         exclude: /node_modules/
  30.       }
  31.     ]
  32.   },
  33.   optimization: {
  34.     minimize: true,
  35.     usedExports: true,
  36.     sideEffects: true,
  37.     concatenateModules: true,
  38.     mangleExports: 'size',
  39.     // restore default async chunking (working setup)
  40.     splitChunks: { chunks: 'async' },
  41.     runtimeChunk: false,
  42.     minimizer: [
  43.       new TerserPlugin({
  44.         parallel: true,
  45.         terserOptions: {
  46.           ecma: 2018,
  47.           compress: {
  48.             passes: 2,
  49.             pure_getters: true,
  50.             unsafe_arrows: true,
  51.             unsafe_methods: true,
  52.             dead_code: true,
  53.             drop_console: true
  54.           },
  55.           mangle: {
  56.             safari10: false
  57.           },
  58.           format: {
  59.             comments: false
  60.           },
  61.           keep_classnames: false,
  62.           keep_fnames: false
  63.         }
  64.       })
  65.     ]
  66.   },
  67.   plugins: [
  68.     ...(process.env.ANALYZE ? [new BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false, reportFilename: 'webpack-report.html' })] : [])
  69.   ],
  70.   experiments: {
  71.     backCompat: false
  72.   },
  73.   performance: {
  74.     hints: false
  75.   }
  76. };
Advertisement
Add Comment
Please, Sign In to add comment