bundle-analyzer
Analyzes JavaScript bundle sizes, identifies large dependencies, and suggests optimizations for webpack, vite, rollup. Use when user asks to "analyze bundle", "optimize bundle size", "reduce bundle", "webpack analysis", or "tree shaking".
What this skill does
# Bundle Analyzer
Analyzes JavaScript bundle sizes, identifies optimization opportunities, and helps reduce bundle size for faster page loads.
## When to Use
- "Analyze my bundle size"
- "Why is my bundle so large?"
- "Optimize webpack bundle"
- "Reduce bundle size"
- "Find large dependencies"
- "Setup bundle analysis"
## Instructions
### 1. Detect Build Tool
Check which bundler is being used:
```bash
# Check package.json
grep -E "(webpack|vite|rollup|parcel|esbuild)" package.json
# Check config files
[ -f "webpack.config.js" ] && echo "Webpack"
[ -f "vite.config.js" ] && echo "Vite"
[ -f "rollup.config.js" ] && echo "Rollup"
```
### 2. Install Analysis Tool
**For Webpack:**
```bash
npm install --save-dev webpack-bundle-analyzer
```
**For Vite:**
```bash
npm install --save-dev rollup-plugin-visualizer
```
**For Rollup:**
```bash
npm install --save-dev rollup-plugin-visualizer
```
**Cross-platform:**
```bash
npm install --save-dev source-map-explorer
```
### 3. Configure Analysis
## Webpack
**webpack.config.js:**
```javascript
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
module.exports = {
// ... other config
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: true,
generateStatsFile: true,
statsFilename: 'bundle-stats.json'
})
]
}
```
**Or for conditional analysis:**
```javascript
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
module.exports = {
plugins: [
process.env.ANALYZE && new BundleAnalyzerPlugin()
].filter(Boolean)
}
```
**package.json scripts:**
```json
{
"scripts": {
"build": "webpack",
"build:analyze": "ANALYZE=true webpack",
"analyze": "webpack-bundle-analyzer dist/stats.json"
}
}
```
## Vite
**vite.config.js:**
```javascript
import { defineConfig } from 'vite'
import { visualizer } from 'rollup-plugin-visualizer'
export default defineConfig({
plugins: [
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
filename: 'dist/stats.html'
})
],
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
utils: ['lodash', 'date-fns']
}
}
}
}
})
```
## Next.js
**next.config.js:**
```javascript
const { ANALYZE } = process.env
module.exports = {
webpack: (config, { isServer }) => {
if (ANALYZE) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: isServer
? '../analyze/server.html'
: './analyze/client.html'
})
)
}
return config
}
}
```
**Or use @next/bundle-analyzer:**
```bash
npm install --save-dev @next/bundle-analyzer
```
```javascript
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true'
})
module.exports = withBundleAnalyzer({
// Next.js config
})
```
**package.json:**
```json
{
"scripts": {
"analyze": "ANALYZE=true next build"
}
}
```
## Create React App
```bash
npm install --save-dev source-map-explorer
```
**package.json:**
```json
{
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'"
}
}
```
### 4. Analyze Bundle
Run analysis:
```bash
npm run build:analyze
# or
npm run analyze
```
Generate report showing:
- Total bundle size
- Breakdown by module
- Treemap visualization
- Gzipped sizes
- Duplicate dependencies
### 5. Identify Issues
**Common issues to look for:**
1. **Large Dependencies**
- Moment.js (use date-fns or dayjs instead)
- Lodash (use lodash-es or individual functions)
- Full libraries when only using small parts
2. **Duplicate Dependencies**
- Same package included multiple times
- Different versions of same package
3. **Unused Code**
- Dead code not tree-shaken
- CSS/JS not actually used
4. **Large Images/Assets**
- Images not optimized
- SVGs not compressed
5. **Development Code in Production**
- Console logs
- Dev-only packages
- Source maps in production
### 6. Suggest Optimizations
## Optimization Strategies
**1. Code Splitting**
```javascript
// Dynamic imports
const HeavyComponent = lazy(() => import('./HeavyComponent'))
// Route-based splitting
const Dashboard = lazy(() => import('./pages/Dashboard'))
const Settings = lazy(() => import('./pages/Settings'))
// Webpack magic comments
const module = import(
/* webpackChunkName: "my-chunk" */
/* webpackPrefetch: true */
'./module'
)
```
**2. Tree Shaking**
```javascript
// ❌ BAD: Imports entire library
import _ from 'lodash'
// ✅ GOOD: Import only what you need
import debounce from 'lodash/debounce'
import throttle from 'lodash/throttle'
// ✅ BETTER: Use lodash-es for tree-shaking
import { debounce, throttle } from 'lodash-es'
```
**3. Replace Large Libraries**
```javascript
// ❌ BAD: Moment.js (heavy)
import moment from 'moment'
// ✅ GOOD: date-fns (modular)
import { format, parseISO } from 'date-fns'
// ✅ GOOD: dayjs (lightweight)
import dayjs from 'dayjs'
```
**4. Lazy Load Routes (React Router)**
```javascript
import { lazy, Suspense } from 'react'
import { BrowserRouter, Routes, Route } from 'react-router-dom'
const Home = lazy(() => import('./pages/Home'))
const About = lazy(() => import('./pages/About'))
const Dashboard = lazy(() => import('./pages/Dashboard'))
function App() {
return (
<BrowserRouter>
<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/dashboard" element={<Dashboard />} />
</Routes>
</Suspense>
</BrowserRouter>
)
}
```
**5. Manual Chunks (Vite/Rollup)**
```javascript
// vite.config.js
export default {
build: {
rollupOptions: {
output: {
manualChunks(id) {
// Vendor chunk for node_modules
if (id.includes('node_modules')) {
if (id.includes('react') || id.includes('react-dom')) {
return 'react-vendor'
}
if (id.includes('@mui')) {
return 'mui-vendor'
}
return 'vendor'
}
}
}
}
}
}
```
**6. Externalize Dependencies (CDN)**
```javascript
// webpack.config.js
module.exports = {
externals: {
react: 'React',
'react-dom': 'ReactDOM',
lodash: '_'
}
}
```
```html
<!-- index.html -->
<script src="https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js"></script>
```
**7. Optimize Images**
```javascript
// next.config.js
module.exports = {
images: {
formats: ['image/avif', 'image/webp'],
deviceSizes: [640, 750, 828, 1080, 1200, 1920],
}
}
// Use next/image
import Image from 'next/image'
<Image
src="/photo.jpg"
width={500}
height={300}
alt="Photo"
/>
```
**8. Remove Unused CSS**
```bash
# Install PurgeCSS
npm install --save-dev @fullhuman/postcss-purgecss
```
```javascript
// postcss.config.js
module.exports = {
plugins: [
require('@fullhuman/postcss-purgecss')({
content: ['./src/**/*.{js,jsx,ts,tsx}'],
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
})
]
}
```
**9. Compression**
```javascript
// webpack.config.js
const CompressionPlugin = require('compression-webpack-plugin')
module.exports = {
plugins: [
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
})
]
}
```
**10. Environment-Specific Code**
```javascript
// webpack.config.js
const webpack = require('webpack')
module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('pRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.