Loading...
Loading...
Loading...
Compare modern JavaScript bundlers: Vite, Webpack, and Turbopack. Understand their strengths, trade-offs, and when to use each.
Vite uses native ES modules in development and Rollup for production builds. Configuration is minimal and intuitive.
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
port: 3000,
open: true,
},
build: {
outDir: 'dist',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
},
},
},
},
});Webpack requires more configuration but offers unmatched flexibility. Loaders and plugins can handle any build requirement.
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
clean: true,
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
],
devServer: {
port: 3000,
hot: true,
open: true,
},
};Turbopack is integrated into Next.js and requires minimal configuration. It's compatible with most Webpack loaders.
// next.config.ts
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
// Turbopack is enabled by default in Next.js 15+
// for development with 'next dev --turbopack'
experimental: {
// Turbopack-specific options
turbo: {
rules: {
// Custom loader rules (Webpack-compatible)
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js',
},
},
resolveAlias: {
// Custom aliases
'@components': './src/components',
},
},
},
};
export default nextConfig;