CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-happypack

webpack speed booster that parallelizes file transformations across multiple Node.js worker processes

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

plugin-configuration.mddocs/

Plugin Configuration

Comprehensive configuration options for HappyPack plugin instances, enabling customization of parallel processing behavior and integration with webpack build pipelines.

Capabilities

Plugin Constructor

Creates a new HappyPack plugin instance with the specified configuration.

/**
 * Creates a new HappyPack plugin instance
 * @param userConfig - Configuration object with loader and thread settings
 * @returns HappyPlugin instance
 */
function HappyPlugin(userConfig);

Usage Examples:

const HappyPack = require('happypack');

// Basic configuration
const plugin = new HappyPack({
  loaders: ['babel-loader?presets[]=es2015']
});

// Advanced configuration
const plugin = new HappyPack({
  id: 'babel',
  threads: 4,
  verbose: false,
  debug: true,
  loaders: [
    {
      loader: 'babel-loader',
      options: {
        presets: ['es2015', 'react']
      }
    }
  ]
});

Configuration Properties

Loader Configuration

Defines the webpack loaders that will be executed in parallel.

interface LoaderConfig {
  /** Loaders to execute in parallel (required) */
  loaders: LoaderSpec[];
  /** Alias for loaders property */
  use?: LoaderSpec[];
}

type LoaderSpec = string | LoaderObject;

interface LoaderObject {
  /** Loader name or path */
  loader?: string;
  /** Alternative to loader property */
  path?: string;
  /** Query string for loader options */
  query?: string | object;
  /** Options object (webpack 2+ style) */
  options?: object;
}

Usage Examples:

// String notation with embedded query
{
  loaders: ['babel-loader?presets[]=es2015']
}

// Object notation with query string
{
  loaders: [
    {
      loader: 'babel-loader',
      query: '?presets[]=es2015'
    }
  ]
}

// Object notation with query object
{
  loaders: [
    {
      loader: 'babel-loader',
      query: {
        presets: ['es2015']
      }
    }
  ]
}

// Webpack 2+ options style
{
  loaders: [
    {
      loader: 'babel-loader',
      options: {
        presets: ['es2015', 'react']
      }
    }
  ]
}

// Multiple loaders in chain
{
  loaders: ['style-loader', 'css-loader', 'less-loader']
}

Thread Management

Controls the number and behavior of worker threads.

interface ThreadConfig {
  /** Number of background threads to spawn (default: 3) */
  threads?: number;
  /** Pre-defined thread pool to share across instances */
  threadPool?: ThreadPool;
}

Usage Examples:

// Custom thread count
{
  threads: 4,
  loaders: ['babel-loader']
}

// Shared thread pool
const sharedPool = HappyPack.ThreadPool({ size: 5 });
{
  threadPool: sharedPool,
  loaders: ['babel-loader']
}

Plugin Identification

Unique identifiers for plugin instances and compiler integration.

interface IdentificationConfig {
  /** Unique ID for this plugin instance (default: '1') */
  id?: string;
  /** Compiler identifier for multi-compiler setups (default: 'default') */
  compilerId?: string;
}

Usage Examples:

// Multiple plugin instances
{
  id: 'jsx',
  loaders: ['babel-loader']
}

{
  id: 'styles',
  loaders: ['style-loader', 'css-loader']
}

// Multi-compiler setup
{
  id: 'main',
  compilerId: 'client',
  loaders: ['babel-loader']
}

Logging and Debug Options

Controls console output and debugging information.

interface LoggingConfig {
  /** Enable status messages to console (default: true) */
  verbose?: boolean;
  /** Enable verbose output during webpack profiling (default: false) */
  verboseWhenProfiling?: boolean;
  /** Enable debug logging (default: process.env.DEBUG === '1') */
  debug?: boolean;
}

Usage Examples:

// Silent mode
{
  verbose: false,
  loaders: ['babel-loader']
}

// Debug mode
{
  debug: true,
  verbose: true,
  loaders: ['babel-loader']
}

// Profiling compatible
{
  verbose: false,
  verboseWhenProfiling: true,
  loaders: ['babel-loader']
}

Platform Compatibility

Platform-specific settings for cross-platform compatibility.

interface CompatibilityConfig {
  /** Windows compatibility messaging mode (default: process.platform === 'win32') */
  bufferedMessaging?: boolean;
}

Usage Examples:

// Force buffered messaging (Windows compatibility)
{
  bufferedMessaging: true,
  loaders: ['babel-loader']
}

// Force unbuffered messaging (Unix optimization)
{
  bufferedMessaging: false,
  loaders: ['babel-loader']
}

Complete Configuration Interface

interface HappyPluginConfig {
  /** Unique identifier for this plugin instance (default: '1') */
  id?: string;
  /** Compiler identifier for multi-compiler setups (default: 'default') */
  compilerId?: string;
  /** Number of background threads to spawn (default: 3) */
  threads?: number;
  /** Pre-defined thread pool to use instead of creating new threads */
  threadPool?: ThreadPool;
  /** Array of loader configurations (required) */
  loaders: LoaderSpec[];
  /** Alias for loaders property - can be used instead of loaders */
  use?: LoaderSpec[];
  /** Enable status logging (default: true) */
  verbose?: boolean;
  /** Enable logging during webpack profiling (default: false) */
  verboseWhenProfiling?: boolean;
  /** Enable debug logging (default: process.env.DEBUG === '1') */
  debug?: boolean;
  /** Windows compatibility messaging mode (default: process.platform === 'win32') */
  bufferedMessaging?: boolean;
}

Note on Deprecated Options:

The following options were available in earlier versions but are now deprecated and will be ignored:

  • tempDir - Temporary directory for worker processes
  • cache - Enable/disable caching
  • cachePath - Cache directory path
  • cacheContext - Cache context directory
  • cacheSignatureGenerator - Custom cache signature function
  • enabled - Enable/disable plugin

Plugin Instance Methods

Methods available on instantiated HappyPlugin objects.

class HappyPlugin {
  /** Plugin name for webpack identification */
  name: string;
  /** Resolved configuration object */
  config: HappyPluginConfig;
  /** Plugin instance ID */
  id: string;
  /** Associated thread pool */
  threadPool: ThreadPool;
  
  /**
   * Webpack plugin interface method - registers plugin hooks
   * @param compiler - Webpack compiler instance
   */
  apply(compiler: object): void;
  
  /**
   * Initialize plugin and start thread pool
   * @param compiler - Webpack compiler instance
   * @param done - Completion callback function
   */
  start(compiler: object, done: function): void;
  
  /** Shutdown thread pool and cleanup resources */
  stop(): void;
  
  /**
   * Compile files using the thread pool
   * @param loaderContext - Webpack loader context
   * @param params - Compilation parameters including sourceCode, sourceMap, resource
   * @param done - Completion callback with (error, result)
   */
  compile(loaderContext: object, params: object, done: function): void;
  
  /**
   * Generate webpack loader request string
   * @param resource - File resource path
   * @returns Formatted loader request
   */
  generateRequest(resource: string): string;
}

Static Properties

Static properties available on the HappyPlugin constructor.

/** List of webpack options that can be serialized to worker processes */
HappyPlugin.SERIALIZABLE_OPTIONS: string[];

/** Reference to HappyThreadPool constructor for convenience */
HappyPlugin.ThreadPool: function;

The SERIALIZABLE_OPTIONS array contains webpack options that can be passed to worker processes:

[
  'amd', 'bail', 'cache', 'context', 'entry', 'externals',
  'debug', 'devtool', 'devServer', 'loader', 'module', 'node',
  'output', 'profile', 'recordsPath', 'recordsInputPath',
  'recordsOutputPath', 'resolve', 'resolveLoader', 'target', 'watch'
]

docs

index.md

loader-integration.md

plugin-configuration.md

thread-pool.md

tile.json