CLI Guide
Deploy Webpack with Bantam CLI
The most powerful and flexible module bundler
Quick start:
# Build your Webpack app
webpack --mode production
# Deploy it
bantam deploy dist
Quick Start
1
Install dependencies
Install project dependencies
npm install
2
Build with Webpack
Bundle your application
webpack --mode production
Creates optimized bundles in the dist directory
3
Deploy with Bantam
Your Webpack app is now live!
bantam deploy dist
Get an instant URL like https://my-app-abc123.bantam.site
Framework Details
Basic Configuration
Configure Webpack for production builds:
webpack.config.js:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
clean: true
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
})
]
};
Use contenthash in filenames for optimal caching.
Optimization
Optimize your bundles for production:
Production optimizations:
module.exports = {
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\/]node_modules[\/]/,
name: 'vendors',
priority: 10
},
common: {
minChunks: 2,
priority: 5,
reuseExistingChunk: true
}
}
},
runtimeChunk: 'single',
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
new CssMinimizerPlugin()
]
}
};
Code splitting improves initial load time but requires proper chunk loading.
Build Output
Webpack generates optimized bundles in dist
:
index.html
- Generated with injected assetsmain.[hash].js
- Main application bundlevendors.[hash].js
- Third-party librariesruntime.[hash].js
- Webpack runtime[name].[hash].css
- Extracted CSS- Asset files with hashed names
Webpack 5 includes persistent caching for faster rebuilds.
Advanced Usage
Custom Domain
Deploy directly to your own domain
bantam deploy ./dist --domain myapp.com
Permanent Deployment
Keep your site online forever (requires login)
bantam deploy ./dist --permanent
Custom Expiry
Set how long your deployment stays online
bantam deploy ./dist --expiry-days 7
Custom Subdomain
Choose your own subdomain on bantam.site
bantam deploy ./dist --subdomain my-project
CI/CD Integration
Add Bantam to your continuous deployment pipeline:
# GitHub Actions example
- name: Deploy to Bantam
run: |
npm install -g @bantamhq/cli
bantam login --token ${{ secrets.BANTAM_TOKEN }}
bantam deploy ./dist --domain myapp.com --permanent
Troubleshooting
Common Issues & Solutions
Quick fixes for deployment challenges
01.Module not found errors?
Configure module resolution:
module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
alias: {
'@': path.resolve(__dirname, 'src'),
'components': path.resolve(__dirname, 'src/components')
}
}
};
02.Assets not loading in production?
Set public path correctly:
module.exports = {
output: {
publicPath: '/',
// Or for CDN
publicPath: 'https://cdn.example.com/'
}
};
// Or set dynamically
__webpack_public_path__ = window.location.origin + '/';
03.Environment variables not working?
Use DefinePlugin or dotenv-webpack:
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
module.exports = {
plugins: [
// Option 1: DefinePlugin
new webpack.DefinePlugin({
'process.env.API_URL': JSON.stringify(process.env.API_URL)
}),
// Option 2: dotenv-webpack
new Dotenv({
systemvars: true
})
]
};
04.Bundle size too large?
Analyze and optimize your bundle:
# Install bundle analyzer
npm install -D webpack-bundle-analyzer
// webpack.config.js
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
plugins: [
new BundleAnalyzerPlugin()
]
};
# Build and analyze
webpack --mode production
05.Dev server config for local development?
Configure webpack-dev-server:
module.exports = {
devServer: {
static: './dist',
hot: true,
open: true,
historyApiFallback: true,
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
}
}
}
};