CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-serverless-webpack

Serverless Framework plugin that bundles Lambda functions with Webpack for optimized JavaScript deployment packages

Pending
Overview
Eval results
Files

development-integration.mddocs/

Development Integration

Local development support with serverless invoke local, serverless-offline integration, watch capabilities, and debugging tools for efficient serverless development workflows.

Capabilities

Local Function Invocation

Enhanced local function invocation with automatic webpack compilation and watch mode support.

# Local invocation commands
sls invoke local --function <name>                    # Invoke function locally with webpack
sls invoke local --function <name> --watch           # Invoke with watch mode
sls invoke local --function <name> --skip-build     # Skip webpack compilation
sls invoke local --function <name> --webpack-use-polling <ms>  # Enable polling mode
sls invoke local --function <name> --data <json>    # Pass data to function
sls invoke local --function <name> --path <file>    # Load data from file

# Global invoke options
--stage <stage>                                       # Set deployment stage
--region <region>                                    # Set AWS region  
--log                                               # Show logs
--docker                                           # Use Docker for invocation

Usage Examples:

# Basic local invocation
sls invoke local --function hello

# Invoke with data and watch mode
sls invoke local --function api --data '{"key": "value"}' --watch

# Invoke with file input and polling
sls invoke local --function processor --path test-data.json --webpack-use-polling 1000

# Skip build for faster iterations
sls invoke local --function quick-test --skip-build

Watch Mode Development

Real-time compilation and execution with file system watching for rapid development cycles.

/**
 * Watch mode configuration and behavior
 */
interface WatchModeOptions {
  enabled: boolean;                   // Enable/disable watch mode
  usePolling: boolean;               // Use polling instead of filesystem events
  pollingInterval: number;           // Polling interval in milliseconds (default: 3000)
  ignored: string[];                 // Patterns to ignore during watch
  watchOptions: {                    // Webpack watch options
    aggregateTimeout: number;        // Delay before rebuilding (default: 300ms)
    poll: boolean | number;          // Polling configuration
    ignored: RegExp | string[];      // Files/directories to ignore
  };
}

Usage Examples:

# Standard watch mode
sls invoke local --function api --watch

# Watch with custom polling for Docker/VM environments
sls invoke local --function api --watch --webpack-use-polling 2000

# Watch specific function during development
sls invoke local --function userHandler --watch --data '{"userId": "123"}'

When watch mode is active:

  • File changes trigger automatic recompilation
  • Function is re-invoked with the same parameters
  • Compilation errors are displayed in real-time
  • Process continues until manually stopped

Serverless Offline Integration

Seamless integration with serverless-offline plugin for local API Gateway simulation.

# Serverless offline commands with webpack
sls offline start                                    # Start offline server with webpack
sls offline start --webpack-no-watch               # Disable webpack watch mode
sls offline start --skip-build                     # Skip initial webpack build  
sls offline start --port <port>                    # Custom port for offline server
sls offline start --host <host>                    # Custom host binding

# Offline-specific webpack options
--webpack-no-watch                                  # Disable automatic webpack watch
--skip-build                                       # Skip webpack compilation entirely

Usage Examples:

# Start offline development server
sls offline start

# Start without webpack watch (manual rebuilds)
sls offline start --webpack-no-watch

# Quick start without initial build
sls offline start --skip-build

# Custom port with webpack watch
sls offline start --port 4000

Integration behavior:

  • Automatic webpack compilation before starting offline server
  • Watch mode enabled by default for live reloading
  • Webpack errors prevent offline server startup
  • Hot reloading of function code during development

Run Command Integration

Enhanced serverless run command with webpack compilation and watch support.

# Run command with webpack integration
sls run                                             # Run function locally with webpack
sls run --watch                                     # Run with watch mode enabled
sls run --function <name>                          # Run specific function
sls run --data <json>                              # Pass data to function
sls run --path <file>                              # Load data from file

# Run-specific options
--watch                                            # Enable watch mode for run command
--stage <stage>                                    # Set deployment stage  
--region <region>                                  # Set AWS region

Usage Examples:

# Run function with webpack
sls run --function processData

# Run with watch mode for development
sls run --function api --watch

# Run with input data
sls run --function calculator --data '{"operation": "add", "numbers": [1, 2, 3]}'

Run command features:

  • Individual function packaging disabled automatically
  • Webpack compilation before execution
  • Watch mode for continuous development
  • Access to full Serverless context

Step Functions Offline Integration

Support for serverless-step-functions-offline plugin with webpack compilation.

# Step Functions offline integration
sls step-functions-offline start                    # Start step functions offline with webpack

# Integration hooks
before:step-functions-offline:start                 # Webpack preparation hook

Usage Examples:

# Start step functions offline development
sls step-functions-offline start

The plugin automatically:

  • Compiles functions before step functions offline startup
  • Prepares webpack build context for step function execution
  • Ensures all functions are available for step function workflows

Development Environment Detection

Automatic detection of local development environment for conditional webpack configuration.

/**
 * Development environment detection
 */
const slsw = require('serverless-webpack');

// Available in webpack configuration
slsw.lib.webpack.isLocal: boolean;  // True when running locally

/**
 * Local environment triggers:
 * - sls invoke local
 * - sls offline start  
 * - sls run
 * - sls step-functions-offline start
 */

Usage Examples:

// webpack.config.js - Environment-specific configuration
const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  
  // Development optimizations
  devtool: slsw.lib.webpack.isLocal ? 'eval-source-map' : 'source-map',
  
  optimization: {
    minimize: !slsw.lib.webpack.isLocal
  },
  
  // Environment-specific externals
  externals: slsw.lib.webpack.isLocal ? [] : ['aws-sdk']
};

Debugging and Inspection

Development tools for debugging webpack compilation and function execution.

# Debug webpack compilation
export SLS_DEBUG=*                                 # Enable debug output
sls invoke local --function <name>

# Inspect webpack output
sls webpack --out debug-build                      # Custom output directory
ls -la debug-build/                               # Inspect compiled files

# Preserve webpack output for inspection
custom:
  webpack:
    keepOutputDirectory: true                      # Keep .webpack directory

Usage Examples:

# Debug webpack compilation issues
export SLS_DEBUG=*
sls invoke local --function problematic-function

# Inspect webpack bundle contents
sls webpack compile --out inspection
find inspection -name "*.js" -exec head -20 {} \;

# Debug with preserved output
sls invoke local --function test --log
ls -la .webpack/service/

Hot Reloading Support

Hot reloading capabilities for rapid development cycles.

/**
 * Hot reloading configuration
 */
interface HotReloadOptions {
  watchMode: boolean;                 // Enable webpack watch mode
  liveReload: boolean;               // Enable live reloading
  hotModuleReplacement: boolean;     // Enable HMR (limited support)
  restartOnChange: boolean;          // Restart process on changes
}

Usage Examples:

# Hot reloading with invoke local
sls invoke local --function api --watch
# Changes to source files trigger automatic recompilation and re-invocation

# Hot reloading with offline
sls offline start
# Changes trigger recompilation and server restart

Hot reloading behavior:

  • File changes detected by webpack watch
  • Automatic recompilation on changes
  • Function re-invocation or server restart
  • Error display without process termination

Development Workflow Optimization

Best practices and optimizations for development workflows.

/**
 * Development workflow optimization techniques
 */
interface DevWorkflowOptions {
  skipBuild: boolean;                // Skip webpack build for faster iteration
  cacheEnabled: boolean;             // Enable webpack caching
  parallelBuilds: boolean;           // Enable parallel compilation
  sourceMapType: string;             // Source map type for debugging
}

Usage Examples:

// webpack.config.js - Development optimizations
const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  
  // Faster development builds
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map',
  
  // Webpack 5 caching for faster rebuilds
  cache: slsw.lib.webpack.isLocal ? {
    type: 'filesystem',
    buildDependencies: {
      config: [__filename]
    }
  } : false,
  
  optimization: {
    minimize: false,  // Disable minification in development
    removeAvailableModules: false,
    removeEmptyChunks: false,
    splitChunks: false
  }
};
# serverless.yml - Development configuration
custom:
  webpack:
    concurrency: 1                    # Reduce memory usage during development
    keepOutputDirectory: true         # Preserve build output for inspection

Testing Integration

Integration with testing frameworks and test execution workflows.

# Testing with webpack compilation
sls invoke local --function testHandler --path test/fixtures/input.json

# Test-specific build configurations
NODE_ENV=test sls webpack compile

Usage Examples:

# Run tests against compiled functions
sls webpack compile
npm test

# Test individual functions
sls invoke local --function userService --path test/user-test-data.json

# Integration testing with offline
sls offline start --stage test &
npm run integration-tests

Error Handling and Recovery

Development-friendly error handling and recovery mechanisms.

/**
 * Development error handling
 */
interface DevErrorHandling {
  continueOnError: boolean;          // Continue watch mode on compilation errors
  errorOverlay: boolean;            // Display error overlay
  logLevel: 'error' | 'warn' | 'info' | 'verbose'; // Logging verbosity
  stackTraceLimit: number;          // Stack trace depth
}

Usage Examples:

# Verbose error reporting
export SLS_DEBUG=*
sls invoke local --function problematic --log

# Continue development despite errors  
sls invoke local --function api --watch
# Watch continues even if compilation fails

Development error features:

  • Detailed webpack compilation errors
  • Stack traces with source map support
  • Non-fatal error handling in watch mode
  • Clear error messages with suggested fixes

Performance Monitoring

Development performance monitoring and optimization tools.

/**
 * Development performance monitoring
 */
interface DevPerformanceMetrics {
  compilationTime: number;           // Webpack compilation duration
  bundleSize: number;               // Output bundle size
  moduleCount: number;              // Number of processed modules
  rebuildTime: number;              // Incremental rebuild time
}

Usage Examples:

# Monitor compilation performance
time sls webpack compile

# Analyze bundle size
sls webpack compile --out analysis
ls -lah analysis/

# Monitor watch rebuild performance
sls invoke local --function api --watch
# Displays rebuild times in watch mode

Performance monitoring includes:

  • Compilation time tracking
  • Bundle size analysis
  • Module resolution timing
  • Memory usage monitoring
  • Incremental build performance

Install with Tessl CLI

npx tessl i tessl/npm-serverless-webpack

docs

build-compilation.md

configuration.md

development-integration.md

index.md

module-packaging.md

packagers.md

utilities.md

webpack-integration.md

tile.json