javascript

examples

examples.js⚑
// ╔══════════════════════════════════════════════════════════════════════════════╗
// β•‘                      BUNDLERS & BUILD TOOLS                                   β•‘
// β•‘              Webpack, Rollup, Vite, esbuild & Modern Tooling                  β•‘
// β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         WHY DO WE NEED BUNDLERS?                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Problems bundlers solve:                                                       β”‚
β”‚                                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Without Bundler:                β”‚  With Bundler:                       β”‚   β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚
β”‚  β”‚  100+ HTTP requests              β”‚  1-5 optimized bundles               β”‚   β”‚
β”‚  β”‚  Large file sizes                β”‚  Minified & compressed               β”‚   β”‚
β”‚  β”‚  No tree-shaking                 β”‚  Dead code eliminated                β”‚   β”‚
β”‚  β”‚  Browser compatibility issues    β”‚  Transpiled for older browsers       β”‚   β”‚
β”‚  β”‚  Manual dependency management    β”‚  Automatic dependency resolution     β”‚   β”‚
β”‚  β”‚  No CSS/image processing         β”‚  All assets processed                β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚   src/        β”‚    β”‚  BUNDLER  β”‚    β”‚  dist/                         β”‚      β”‚
β”‚  β”‚  β”œβ”€ index.js  │───►│  Process  │───►│  └─ bundle.js (optimized)      β”‚      β”‚
β”‚  β”‚  β”œβ”€ utils.js  β”‚    β”‚  & Bundle β”‚    β”‚                                β”‚      β”‚
β”‚  β”‚  └─ style.css β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                              β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// ════════════════════════════════════════════════════════════════════════════════
// 1. BUNDLERS COMPARISON
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         POPULAR BUNDLERS                                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚              β”‚  Webpack      β”‚  Rollup       β”‚  Vite       β”‚  esbuild     β”‚ β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚  β”‚  Released    β”‚  2012         β”‚  2015         β”‚  2020       β”‚  2020        β”‚ β”‚
β”‚  β”‚  Best For    β”‚  Apps         β”‚  Libraries    β”‚  Dev + Apps β”‚  Speed       β”‚ β”‚
β”‚  β”‚  Language    β”‚  JavaScript   β”‚  JavaScript   β”‚  JavaScript β”‚  Go          β”‚ β”‚
β”‚  β”‚  Config      β”‚  Complex      β”‚  Moderate     β”‚  Minimal    β”‚  Simple      β”‚ β”‚
β”‚  β”‚  Dev Server  β”‚  Plugin       β”‚  Plugin       β”‚  Built-in   β”‚  Plugin      β”‚ β”‚
β”‚  β”‚  HMR         β”‚  Yes          β”‚  Plugin       β”‚  Yes (fast) β”‚  Plugin      β”‚ β”‚
β”‚  β”‚  Tree-shake  β”‚  Yes          β”‚  Excellent    β”‚  Yes        β”‚  Yes         β”‚ β”‚
β”‚  β”‚  Code Split  β”‚  Yes          β”‚  Yes          β”‚  Yes        β”‚  Yes         β”‚ β”‚
β”‚  β”‚  Speed       β”‚  Moderate     β”‚  Fast         β”‚  Very Fast  β”‚  Blazing     β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                                                  β”‚
β”‚  Modern Alternatives:                                                           β”‚
β”‚  β€’ Parcel - Zero config bundler                                                 β”‚
β”‚  β€’ SWC - Rust-based transformer (used by Next.js)                              β”‚
β”‚  β€’ Turbopack - Rust-based bundler (Vercel)                                     β”‚
β”‚  β€’ Bun - All-in-one JavaScript runtime with bundler                            β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

console.log('Bundlers & Build Tools Examples');
console.log('================================\n');

// ════════════════════════════════════════════════════════════════════════════════
// 2. WEBPACK CONFIGURATION
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         WEBPACK CONFIGURATION                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  File: webpack.config.js                                                        β”‚
β”‚                                                                                  β”‚
β”‚  Key concepts:                                                                  β”‚
β”‚  β€’ Entry: Starting point(s) for bundling                                        β”‚
β”‚  β€’ Output: Where to emit bundles                                                β”‚
β”‚  β€’ Loaders: Transform non-JS files (CSS, images, etc.)                         β”‚
β”‚  β€’ Plugins: Extend webpack functionality                                        β”‚
β”‚  β€’ Mode: 'development' | 'production' | 'none'                                  β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Example Webpack configuration (as JavaScript object for reference)
const webpackConfig = {
  // Entry point(s)
  entry: './src/index.js',

  // Can have multiple entries
  // entry: {
  //     main: './src/index.js',
  //     vendor: './src/vendor.js'
  // },

  // Output configuration
  output: {
    path: '/dist', // Would use path.resolve(__dirname, 'dist')
    filename: '[name].[contenthash].js', // Cache-busting with hash
    clean: true, // Clean dist folder before build
  },

  // Mode: affects optimizations
  mode: 'production', // or 'development'

  // Module rules (loaders)
  module: {
    rules: [
      // JavaScript/JSX with Babel
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react'],
          },
        },
      },

      // CSS
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },

      // SCSS/SASS
      {
        test: /\.scss$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },

      // Images
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
      },

      // Fonts
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: 'asset/resource',
      },
    ],
  },

  // Plugins
  plugins: [
    // HtmlWebpackPlugin - generates HTML
    // new HtmlWebpackPlugin({ template: './src/index.html' }),
    // MiniCssExtractPlugin - extracts CSS to files
    // new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' }),
    // DefinePlugin - define environment variables
    // new webpack.DefinePlugin({
    //     'process.env.NODE_ENV': JSON.stringify('production')
    // })
  ],

  // Resolve configuration
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    alias: {
      '@': '/src', // Would use path.resolve(__dirname, 'src')
      '@components': '/src/components',
    },
  },

  // Development server
  devServer: {
    static: './dist',
    hot: true, // Hot Module Replacement
    port: 3000,
    open: true, // Open browser
  },

  // Optimization
  optimization: {
    splitChunks: {
      chunks: 'all',
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendors',
          chunks: 'all',
        },
      },
    },
    minimize: true,
  },

  // Source maps for debugging
  devtool: 'source-map',
};

console.log('1. Webpack Configuration Example:');
console.log('   Entry:', webpackConfig.entry);
console.log('   Output:', webpackConfig.output.filename);
console.log('   Mode:', webpackConfig.mode);
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 3. ROLLUP CONFIGURATION
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         ROLLUP CONFIGURATION                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  File: rollup.config.js                                                         β”‚
β”‚                                                                                  β”‚
β”‚  Best for: Libraries, packages (excellent tree-shaking)                         β”‚
β”‚                                                                                  β”‚
β”‚  Key features:                                                                  β”‚
β”‚  β€’ Multiple output formats (ESM, CJS, UMD, IIFE)                                β”‚
β”‚  β€’ Superior tree-shaking                                                        β”‚
β”‚  β€’ Smaller bundle sizes for libraries                                           β”‚
β”‚  β€’ Clean, readable output                                                       β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Example Rollup configuration
const rollupConfig = {
  // Input
  input: 'src/index.js',

  // Multiple outputs for different environments
  output: [
    // ES Module format (modern browsers, bundlers)
    {
      file: 'dist/my-library.esm.js',
      format: 'esm',
      sourcemap: true,
    },

    // CommonJS format (Node.js)
    {
      file: 'dist/my-library.cjs.js',
      format: 'cjs',
      sourcemap: true,
    },

    // UMD format (browsers, AMD, CommonJS)
    {
      file: 'dist/my-library.umd.js',
      format: 'umd',
      name: 'MyLibrary', // Global variable name
      sourcemap: true,
    },

    // IIFE format (browsers, script tag)
    {
      file: 'dist/my-library.iife.js',
      format: 'iife',
      name: 'MyLibrary',
      sourcemap: true,
    },
  ],

  // External dependencies (don't bundle these)
  external: ['react', 'react-dom', 'lodash'],

  // Plugins
  plugins: [
    // @rollup/plugin-node-resolve - resolve node_modules
    // resolve(),
    // @rollup/plugin-commonjs - convert CommonJS to ES modules
    // commonjs(),
    // @rollup/plugin-babel - transpile with Babel
    // babel({ babelHelpers: 'bundled', exclude: 'node_modules/**' }),
    // @rollup/plugin-terser - minify
    // terser()
  ],
};

console.log('2. Rollup Configuration Example:');
console.log('   Input:', rollupConfig.input);
console.log(
  '   Output formats:',
  rollupConfig.output.map((o) => o.format).join(', ')
);
console.log('   External deps:', rollupConfig.external.join(', '));
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 4. VITE CONFIGURATION
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           VITE CONFIGURATION                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  File: vite.config.js                                                           β”‚
β”‚                                                                                  β”‚
β”‚  Why Vite is fast:                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚                                                                         β”‚   β”‚
β”‚  β”‚  Development:                                                           β”‚   β”‚
β”‚  β”‚  β€’ No bundling! Uses native ES modules                                  β”‚   β”‚
β”‚  β”‚  β€’ esbuild for fast transforms                                          β”‚   β”‚
β”‚  β”‚  β€’ On-demand file serving                                               β”‚   β”‚
β”‚  β”‚  β€’ Instant HMR                                                          β”‚   β”‚
β”‚  β”‚                                                                         β”‚   β”‚
β”‚  β”‚  Production:                                                            β”‚   β”‚
β”‚  β”‚  β€’ Rollup for optimized builds                                          β”‚   β”‚
β”‚  β”‚  β€’ Code splitting                                                       β”‚   β”‚
β”‚  β”‚  β€’ CSS code splitting                                                   β”‚   β”‚
β”‚  β”‚                                                                         β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                                  β”‚
β”‚  Commands:                                                                      β”‚
β”‚  β€’ npm create vite@latest my-app                                                β”‚
β”‚  β€’ npm run dev    (development server)                                          β”‚
β”‚  β€’ npm run build  (production build)                                            β”‚
β”‚  β€’ npm run preview (preview production build)                                   β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Example Vite configuration (import { defineConfig } from 'vite')
const viteConfig = {
  // Base public path
  base: '/',

  // Development server
  server: {
    port: 3000,
    open: true,
    cors: true,
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },

  // Build configuration
  build: {
    outDir: 'dist',
    sourcemap: true,
    minify: 'esbuild', // or 'terser' for more compression

    // Library mode (for building libraries)
    // lib: {
    //     entry: 'src/index.js',
    //     name: 'MyLib',
    //     formats: ['es', 'cjs', 'umd']
    // },

    // Rollup options
    rollupOptions: {
      // External deps for library mode
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },

  // CSS configuration
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/variables.scss";',
      },
    },
    modules: {
      localsConvention: 'camelCase',
    },
  },

  // Resolve (alias)
  resolve: {
    alias: {
      '@': '/src',
      '@components': '/src/components',
    },
  },

  // Plugins
  plugins: [
    // @vitejs/plugin-react - React support
    // react(),
    // @vitejs/plugin-vue - Vue support
    // vue(),
  ],

  // Optimization
  optimizeDeps: {
    include: ['lodash-es'], // Pre-bundle these
    exclude: ['some-package'], // Don't pre-bundle
  },
};

console.log('3. Vite Configuration Example:');
console.log('   Server port:', viteConfig.server.port);
console.log('   Output dir:', viteConfig.build.outDir);
console.log('   Minifier:', viteConfig.build.minify);
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 5. ESBUILD CONFIGURATION
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         ESBUILD CONFIGURATION                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Why esbuild is blazing fast:                                                   β”‚
β”‚  β€’ Written in Go (compiled, parallel execution)                                 β”‚
β”‚  β€’ 10-100x faster than other bundlers                                           β”‚
β”‚  β€’ Used by Vite for development transforms                                      β”‚
β”‚                                                                                  β”‚
β”‚  CLI usage:                                                                     β”‚
β”‚  esbuild src/index.js --bundle --outfile=dist/bundle.js                        β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// esbuild API configuration
const esbuildConfig = {
  // Entry points
  entryPoints: ['src/index.js'],

  // Output
  outfile: 'dist/bundle.js',
  // Or for multiple outputs:
  // outdir: 'dist',

  // Bundle dependencies
  bundle: true,

  // Minify
  minify: true,

  // Source maps
  sourcemap: true,

  // Target environment
  target: ['es2020', 'chrome80', 'firefox78', 'safari13'],

  // Format
  format: 'esm', // 'iife', 'cjs', 'esm'

  // Platform
  platform: 'browser', // 'browser', 'node', 'neutral'

  // External packages
  external: ['react', 'react-dom'],

  // Define globals
  define: {
    'process.env.NODE_ENV': '"production"',
  },

  // Loaders
  loader: {
    '.png': 'file',
    '.svg': 'text',
    '.json': 'json',
  },

  // Plugins (limited compared to webpack)
  plugins: [],
};

console.log('4. esbuild Configuration Example:');
console.log('   Entry:', esbuildConfig.entryPoints);
console.log('   Format:', esbuildConfig.format);
console.log('   Platform:', esbuildConfig.platform);
console.log('   Target:', esbuildConfig.target.join(', '));
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 6. KEY BUNDLER CONCEPTS
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         KEY BUNDLER CONCEPTS                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  1. ENTRY POINTS                                                                β”‚
β”‚     Starting file(s) for dependency graph                                       β”‚
β”‚                                                                                  β”‚
β”‚  2. OUTPUT                                                                      β”‚
β”‚     Where and how to write bundled files                                        β”‚
β”‚                                                                                  β”‚
β”‚  3. LOADERS/TRANSFORMS                                                          β”‚
β”‚     Process non-JS files (CSS, images, TypeScript)                              β”‚
β”‚                                                                                  β”‚
β”‚  4. PLUGINS                                                                     β”‚
β”‚     Extend bundler functionality                                                β”‚
β”‚                                                                                  β”‚
β”‚  5. CODE SPLITTING                                                              β”‚
β”‚     Split code into smaller chunks for lazy loading                             β”‚
β”‚                                                                                  β”‚
β”‚  6. TREE SHAKING                                                                β”‚
β”‚     Remove unused code (dead code elimination)                                  β”‚
β”‚                                                                                  β”‚
β”‚  7. HOT MODULE REPLACEMENT (HMR)                                                β”‚
β”‚     Update modules without full page refresh                                    β”‚
β”‚                                                                                  β”‚
β”‚  8. SOURCE MAPS                                                                 β”‚
β”‚     Map bundled code back to original source                                    β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Simulating bundler concepts

// ─── Code Splitting Example ────────────────────────────────────────────────────

console.log('5. Key Bundler Concepts:');
console.log('');

// Dynamic import for code splitting
async function loadFeature(featureName) {
  console.log(`   Loading feature: ${featureName}`);

  // This would create a separate chunk in a real bundler
  // const module = await import(`./features/${featureName}.js`);

  // Simulated dynamic import
  const features = {
    dashboard: { render: () => '<Dashboard />' },
    settings: { render: () => '<Settings />' },
    profile: { render: () => '<Profile />' },
  };

  return features[featureName];
}

// Route-based code splitting
const routes = {
  '/': () => import('./pages/home.js'),
  '/about': () => import('./pages/about.js'),
  '/dashboard': () => import('./pages/dashboard.js'),
};

console.log('   Code Splitting (dynamic imports):');
console.log(
  '   Routes configured for lazy loading:',
  Object.keys(routes).join(', ')
);
console.log('');

// ─── Tree Shaking Example ──────────────────────────────────────────────────────

// Only `add` will be included if only `add` is imported
const mathUtils = {
  add: (a, b) => a + b,
  subtract: (a, b) => a - b,
  multiply: (a, b) => a * b,
  divide: (a, b) => a / b,
};

// Tree shaking works best with:
// 1. ES Modules (import/export)
// 2. Pure functions (no side effects)
// 3. Proper sideEffects field in package.json

console.log('   Tree Shaking:');
console.log('   - Works with ES Modules (static analysis)');
console.log('   - Removes unused exports');
console.log('   - sideEffects: false in package.json');
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 7. PACKAGE.JSON SCRIPTS
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         PACKAGE.JSON SCRIPTS                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Common scripts for different bundlers:                                         β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

const packageJsonScripts = {
  // Webpack
  webpack: {
    dev: 'webpack serve --mode development',
    build: 'webpack --mode production',
    'build:dev': 'webpack --mode development',
    analyze: 'webpack --profile --json > stats.json',
  },

  // Rollup
  rollup: {
    dev: 'rollup -c -w',
    build: 'rollup -c',
    'build:prod': 'NODE_ENV=production rollup -c',
  },

  // Vite
  vite: {
    dev: 'vite',
    build: 'vite build',
    preview: 'vite preview',
    'build:lib': 'vite build --mode lib',
  },

  // esbuild
  esbuild: {
    dev: 'esbuild src/index.js --bundle --watch --servedir=dist',
    build: 'esbuild src/index.js --bundle --minify --outfile=dist/bundle.js',
  },
};

console.log('6. Package.json Scripts:');
console.log(
  '   Webpack:',
  JSON.stringify(packageJsonScripts.webpack, null, 2).split('\n').join('\n   ')
);
console.log(
  '   Vite:',
  JSON.stringify(packageJsonScripts.vite, null, 2).split('\n').join('\n   ')
);
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 8. COMMON PLUGINS
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         COMMON PLUGINS                                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Webpack Plugins:                                                               β”‚
β”‚  β€’ HtmlWebpackPlugin - Generate HTML                                            β”‚
β”‚  β€’ MiniCssExtractPlugin - Extract CSS                                           β”‚
β”‚  β€’ CopyWebpackPlugin - Copy static files                                        β”‚
β”‚  β€’ DefinePlugin - Define environment variables                                  β”‚
β”‚  β€’ BundleAnalyzerPlugin - Visualize bundle                                      β”‚
β”‚                                                                                  β”‚
β”‚  Rollup Plugins:                                                                β”‚
β”‚  β€’ @rollup/plugin-node-resolve - Resolve node_modules                           β”‚
β”‚  β€’ @rollup/plugin-commonjs - Convert CommonJS to ESM                           β”‚
β”‚  β€’ @rollup/plugin-babel - Babel transpilation                                   β”‚
β”‚  β€’ @rollup/plugin-terser - Minification                                        β”‚
β”‚  β€’ rollup-plugin-visualizer - Bundle visualization                              β”‚
β”‚                                                                                  β”‚
β”‚  Vite Plugins:                                                                  β”‚
β”‚  β€’ @vitejs/plugin-react - React support                                         β”‚
β”‚  β€’ @vitejs/plugin-vue - Vue support                                             β”‚
β”‚  β€’ vite-plugin-pwa - PWA support                                                β”‚
β”‚  β€’ vite-plugin-compression - Gzip/Brotli                                        β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

console.log('7. Common Plugins by Bundler:');
console.log(
  '   Webpack: HtmlWebpackPlugin, MiniCssExtractPlugin, DefinePlugin'
);
console.log('   Rollup: @rollup/plugin-node-resolve, @rollup/plugin-commonjs');
console.log(
  '   Vite: @vitejs/plugin-react, @vitejs/plugin-vue, vite-plugin-pwa'
);
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 9. BUILD OPTIMIZATION TECHNIQUES
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      BUILD OPTIMIZATION TECHNIQUES                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  1. Code Splitting                                                              β”‚
β”‚     β€’ Route-based splitting                                                     β”‚
β”‚     β€’ Component-based splitting                                                 β”‚
β”‚     β€’ Vendor chunk separation                                                   β”‚
β”‚                                                                                  β”‚
β”‚  2. Minification                                                                β”‚
β”‚     β€’ JavaScript: Terser, esbuild                                               β”‚
β”‚     β€’ CSS: cssnano, clean-css                                                   β”‚
β”‚     β€’ HTML: html-minifier                                                       β”‚
β”‚                                                                                  β”‚
β”‚  3. Compression                                                                 β”‚
β”‚     β€’ Gzip (.gz files)                                                          β”‚
β”‚     β€’ Brotli (.br files)                                                        β”‚
β”‚                                                                                  β”‚
β”‚  4. Caching                                                                     β”‚
β”‚     β€’ Content hash in filenames                                                 β”‚
β”‚     β€’ Long-term caching for static assets                                       β”‚
β”‚                                                                                  β”‚
β”‚  5. Asset Optimization                                                          β”‚
β”‚     β€’ Image compression                                                         β”‚
β”‚     β€’ Font subsetting                                                           β”‚
β”‚     β€’ SVG optimization                                                          β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Example optimization configuration
const optimizationConfig = {
  // Webpack optimization
  webpack: {
    optimization: {
      minimize: true,
      minimizer: ['terser-webpack-plugin', 'css-minimizer-webpack-plugin'],
      splitChunks: {
        chunks: 'all',
        maxSize: 244000, // 244kb max chunk size
        cacheGroups: {
          vendor: {
            test: /[\\/]node_modules[\\/]/,
            name: 'vendors',
            chunks: 'all',
            priority: 10,
          },
          common: {
            minChunks: 2,
            priority: 5,
            reuseExistingChunk: true,
          },
        },
      },
      runtimeChunk: 'single',
    },
  },

  // Content hashing for cache busting
  output: {
    filename: '[name].[contenthash:8].js',
    chunkFilename: '[name].[contenthash:8].chunk.js',
    assetModuleFilename: 'assets/[name].[contenthash:8][ext]',
  },
};

console.log('8. Optimization Techniques:');
console.log('   Chunk splitting:', 'all chunks, vendor separation');
console.log('   Max chunk size:', '244kb');
console.log('   Cache busting:', 'contenthash in filenames');
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 10. ENVIRONMENT CONFIGURATION
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      ENVIRONMENT CONFIGURATION                                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Files:                                                                         β”‚
β”‚  β€’ .env              - Default                                                  β”‚
β”‚  β€’ .env.local        - Local overrides (gitignored)                             β”‚
β”‚  β€’ .env.development  - Development mode                                         β”‚
β”‚  β€’ .env.production   - Production mode                                          β”‚
β”‚                                                                                  β”‚
β”‚  Access:                                                                        β”‚
β”‚  β€’ Vite: import.meta.env.VITE_API_URL                                           β”‚
β”‚  β€’ Webpack: process.env.REACT_APP_API_URL                                       β”‚
β”‚                                                                                  β”‚
β”‚  Important:                                                                     β”‚
β”‚  β€’ Only prefixed variables are exposed to client                                β”‚
β”‚  β€’ VITE_ prefix for Vite                                                        β”‚
β”‚  β€’ REACT_APP_ prefix for Create React App                                       β”‚
β”‚  β€’ NEVER expose secrets to client-side code!                                    β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Environment configuration example
const envConfig = {
  development: {
    API_URL: 'http://localhost:3000',
    DEBUG: true,
    LOG_LEVEL: 'debug',
  },
  production: {
    API_URL: 'https://api.production.com',
    DEBUG: false,
    LOG_LEVEL: 'error',
  },
  test: {
    API_URL: 'http://localhost:3000',
    DEBUG: true,
    LOG_LEVEL: 'warn',
  },
};

// .env file example content
const dotEnvExample = `
# .env.development
VITE_API_URL=http://localhost:3000
VITE_DEBUG=true

# .env.production  
VITE_API_URL=https://api.production.com
VITE_DEBUG=false

# Usage in code:
# const apiUrl = import.meta.env.VITE_API_URL
`.trim();

console.log('9. Environment Configuration:');
console.log('   Development API:', envConfig.development.API_URL);
console.log('   Production API:', envConfig.production.API_URL);
console.log('   Prefix: VITE_ (Vite), REACT_APP_ (CRA)');
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// 11. MONOREPO BUILD TOOLS
// ════════════════════════════════════════════════════════════════════════════════

/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         MONOREPO BUILD TOOLS                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                  β”‚
β”‚  Popular monorepo tools:                                                        β”‚
β”‚  β€’ Turborepo - Fast build system with caching                                   β”‚
β”‚  β€’ Nx - Extensible build framework                                              β”‚
β”‚  β€’ Lerna - Original monorepo tool                                               β”‚
β”‚  β€’ pnpm workspaces - Built into pnpm                                            β”‚
β”‚                                                                                  β”‚
β”‚  Structure:                                                                     β”‚
β”‚  β”œβ”€β”€ packages/                                                                  β”‚
β”‚  β”‚   β”œβ”€β”€ ui/           (shared UI components)                                  β”‚
β”‚  β”‚   β”œβ”€β”€ utils/        (shared utilities)                                      β”‚
β”‚  β”‚   └── config/       (shared config)                                         β”‚
β”‚  β”œβ”€β”€ apps/                                                                      β”‚
β”‚  β”‚   β”œβ”€β”€ web/          (web application)                                       β”‚
β”‚  β”‚   └── mobile/       (mobile application)                                    β”‚
β”‚  β”œβ”€β”€ package.json                                                               β”‚
β”‚  └── turbo.json                                                                 β”‚
β”‚                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

// Turborepo configuration example
const turboConfig = {
  $schema: 'https://turbo.build/schema.json',
  pipeline: {
    build: {
      dependsOn: ['^build'],
      outputs: ['dist/**', '.next/**'],
    },
    test: {
      dependsOn: ['build'],
      outputs: [],
    },
    lint: {
      outputs: [],
    },
    dev: {
      cache: false,
    },
  },
};

console.log('10. Monorepo Tools:');
console.log('    Turborepo: Fast builds with caching');
console.log('    Nx: Extensible, great for large teams');
console.log('    Lerna: Original, now maintained by Nx');
console.log('');

// ════════════════════════════════════════════════════════════════════════════════
// SUMMARY
// ════════════════════════════════════════════════════════════════════════════════

console.log(`
╔══════════════════════════════════════════════════════════════════════════════╗
β•‘                  BUNDLERS & BUILD TOOLS - COMPLETE                           β•‘
╠══════════════════════════════════════════════════════════════════════════════╣
β•‘                                                                              β•‘
β•‘  Bundler Selection Guide:                                                    β•‘
β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β•‘
β•‘  β”‚  Use Case      β”‚  Recommended                                          β”‚ β•‘
β•‘  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β•‘
β•‘  β”‚  Web App (SPA) β”‚  Vite, Webpack                                        β”‚ β•‘
β•‘  β”‚  Library       β”‚  Rollup, Vite (lib mode)                              β”‚ β•‘
β•‘  β”‚  Fast Dev      β”‚  Vite, esbuild                                        β”‚ β•‘
β•‘  β”‚  Complex App   β”‚  Webpack (most plugins/loaders)                       β”‚ β•‘
β•‘  β”‚  Speed Focus   β”‚  esbuild, Vite                                        β”‚ β•‘
β•‘  β”‚  Zero Config   β”‚  Parcel, Vite                                         β”‚ β•‘
β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘
β•‘                                                                              β•‘
β•‘  Key Concepts:                                                               β•‘
β•‘  β€’ Entry points β†’ Bundle β†’ Output                                           β•‘
β•‘  β€’ Loaders transform files (CSS, images, TypeScript)                        β•‘
β•‘  β€’ Plugins extend functionality                                             β•‘
β•‘  β€’ Tree shaking removes unused code                                         β•‘
β•‘  β€’ Code splitting creates lazy-loaded chunks                                β•‘
β•‘  β€’ HMR updates modules without refresh                                      β•‘
β•‘                                                                              β•‘
β•‘  Modern Trends:                                                              β•‘
β•‘  β€’ Rust/Go based tools (esbuild, SWC, Turbopack)                            β•‘
β•‘  β€’ Native ES modules in development (Vite)                                  β•‘
β•‘  β€’ Zero-config approaches                                                   β•‘
β•‘  β€’ Incremental builds and caching                                           β•‘
β•‘                                                                              β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
`);
Examples - JavaScript Tutorial | DeepML