or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdcore-compilation.mddevelopment-tools.mdindex.mdmodule-system.mdoptimization.mdplugins.mdruntime-system.mdutilities.md

development-tools.mddocs/

0

# Development Tools

1

2

Webpack's development tools provide a comprehensive suite of plugins and features designed to enhance the developer experience. These tools enable hot module replacement, source map generation, progress reporting, file watching, debugging capabilities, and seamless integration with development servers for efficient development workflows.

3

4

## Capabilities

5

6

### Hot Module Replacement

7

8

Hot Module Replacement (HMR) allows modules to be updated at runtime without requiring a full page refresh, dramatically improving development speed and preserving application state.

9

10

```javascript { .api }

11

/**

12

* Enables Hot Module Replacement for faster development cycles

13

* @param options - HMR configuration options

14

*/

15

class HotModuleReplacementPlugin {

16

constructor(options?: {

17

/** Enable multi-step mode for better HMR performance */

18

multiStep?: boolean;

19

/** Timeout for full rebuild in milliseconds */

20

fullBuildTimeout?: number;

21

/** Timeout for HMR requests in milliseconds */

22

requestTimeout?: number;

23

});

24

}

25

```

26

27

**Usage Examples:**

28

29

```javascript

30

const webpack = require("webpack");

31

32

module.exports = {

33

mode: 'development',

34

entry: './src/index.js',

35

devServer: {

36

hot: true,

37

port: 3000

38

},

39

plugins: [

40

new webpack.HotModuleReplacementPlugin({

41

multiStep: true,

42

fullBuildTimeout: 200,

43

requestTimeout: 10000

44

})

45

]

46

};

47

48

// In your application code

49

if (module.hot) {

50

module.hot.accept('./component.js', () => {

51

console.log('Component updated!');

52

// Re-render component without page refresh

53

});

54

55

// Handle disposal

56

module.hot.dispose(() => {

57

// Cleanup before module replacement

58

});

59

}

60

```

61

62

### Source Map Generation

63

64

Source maps enable debugging of bundled code by mapping minified/transformed code back to original source files with precise line and column information.

65

66

```javascript { .api }

67

/**

68

* Generates source maps with fine-grained control over format and output

69

* @param options - Source map generation options

70

*/

71

class SourceMapDevToolPlugin {

72

constructor(options?: {

73

/** Output filename pattern for source maps */

74

filename?: string | false;

75

/** Include files matching these patterns */

76

include?: string | RegExp | Array<string | RegExp>;

77

/** Exclude files matching these patterns */

78

exclude?: string | RegExp | Array<string | RegExp>;

79

/** Template for module filenames in source maps */

80

moduleFilenameTemplate?: string | ((info: ModuleFilenameTemplateInfo) => string);

81

/** Fallback template when main template fails */

82

fallbackModuleFilenameTemplate?: string | ((info: ModuleFilenameTemplateInfo) => string);

83

/** String appended to source map comment */

84

append?: string | false;

85

/** Include module names in source maps */

86

module?: boolean;

87

/** Include column information in source maps */

88

columns?: boolean;

89

/** Enable line-to-line mode for faster source maps */

90

lineToLine?: boolean | { test?: RegExp | Array<RegExp> };

91

/** Exclude source content from source maps */

92

noSources?: boolean;

93

/** Public path for source map URLs */

94

publicPath?: string;

95

/** Context path for file URLs */

96

fileContext?: string;

97

/** Source root URL prefix */

98

sourceRoot?: string;

99

});

100

}

101

102

/**

103

* Fast source maps using eval() for development builds

104

* @param options - Eval source map options

105

*/

106

class EvalSourceMapDevToolPlugin {

107

constructor(options?: {

108

/** Include files matching these patterns */

109

include?: string | RegExp | Array<string | RegExp>;

110

/** Exclude files matching these patterns */

111

exclude?: string | RegExp | Array<string | RegExp>;

112

/** Template for module filenames */

113

moduleFilenameTemplate?: string | ((info: ModuleFilenameTemplateInfo) => string);

114

/** Include module names */

115

module?: boolean;

116

/** Include column information */

117

columns?: boolean;

118

/** Enable line-to-line mode */

119

lineToLine?: boolean | { test?: RegExp | Array<RegExp> };

120

});

121

}

122

123

/**

124

* Wraps modules in eval() statements for better debugging without source maps

125

* @param options - Eval dev tool options

126

*/

127

class EvalDevToolModulePlugin {

128

constructor(options?: {

129

/** Template for module filenames in eval statements */

130

moduleFilenameTemplate?: string | ((info: ModuleFilenameTemplateInfo) => string);

131

/** Comment template for source URLs */

132

sourceUrlComment?: string;

133

});

134

}

135

136

interface ModuleFilenameTemplateInfo {

137

identifier: string;

138

shortIdentifier: string;

139

resource: string;

140

resourcePath: string;

141

absoluteResourcePath: string;

142

loaders: string;

143

allLoaders: string;

144

query: string;

145

moduleId: string | number;

146

hash: string;

147

namespace: string;

148

}

149

```

150

151

**Usage Examples:**

152

153

```javascript

154

const webpack = require("webpack");

155

156

// Production source maps

157

module.exports = {

158

mode: 'production',

159

devtool: false, // Disable default devtool

160

plugins: [

161

new webpack.SourceMapDevToolPlugin({

162

filename: '[file].map[query]',

163

include: /\.(js|css)$/,

164

exclude: /vendor/,

165

moduleFilenameTemplate: 'webpack://[namespace]/[resource-path]?[loaders]',

166

publicPath: 'https://cdn.example.com/sourcemaps/',

167

columns: false,

168

noSources: false

169

})

170

]

171

};

172

173

// Development eval source maps

174

module.exports = {

175

mode: 'development',

176

devtool: false,

177

plugins: [

178

new webpack.EvalSourceMapDevToolPlugin({

179

include: /\.js$/,

180

exclude: /node_modules/,

181

moduleFilenameTemplate: 'webpack:///[resource-path]',

182

columns: true

183

})

184

]

185

};

186

187

// Eval debugging without source maps

188

module.exports = {

189

mode: 'development',

190

devtool: false,

191

plugins: [

192

new webpack.EvalDevToolModulePlugin({

193

moduleFilenameTemplate: 'webpack:///[resource-path]',

194

sourceUrlComment: '\n//# sourceURL=[url]'

195

})

196

]

197

};

198

```

199

200

### Progress Reporting

201

202

The ProgressPlugin provides detailed feedback about compilation progress, helping developers understand build performance and identify bottlenecks.

203

204

```javascript { .api }

205

/**

206

* Reports compilation progress during builds with customizable handlers

207

* @param options - Progress reporting configuration

208

*/

209

class ProgressPlugin {

210

constructor(options?: {

211

/** Show active module count */

212

activeModules?: boolean;

213

/** Show entries progress */

214

entries?: boolean;

215

/** Custom progress handler function */

216

handler?: (percentage: number, message: string, ...args: string[]) => void;

217

/** Show modules progress */

218

modules?: boolean;

219

/** Expected number of modules for percentage calculation */

220

modulesCount?: number;

221

/** Enable performance profiling */

222

profile?: boolean;

223

/** Show dependencies progress */

224

dependencies?: boolean;

225

/** Expected number of dependencies */

226

dependenciesCount?: number;

227

/** Method for calculating percentage */

228

percentBy?: 'entries' | 'modules' | 'dependencies' | null;

229

});

230

}

231

```

232

233

**Usage Examples:**

234

235

```javascript

236

const webpack = require("webpack");

237

238

module.exports = {

239

plugins: [

240

// Basic progress reporting

241

new webpack.ProgressPlugin(),

242

243

// Custom progress handler

244

new webpack.ProgressPlugin({

245

activeModules: true,

246

entries: true,

247

modules: true,

248

dependencies: true,

249

profile: true,

250

handler: (percentage, message, ...args) => {

251

const percent = Math.round(percentage * 100);

252

const timestamp = new Date().toLocaleTimeString();

253

console.log(`[${timestamp}] ${percent}% ${message} ${args.join(' ')}`);

254

}

255

}),

256

257

// Integration with build tools

258

new webpack.ProgressPlugin({

259

handler: (percentage, message, ...args) => {

260

if (process.env.CI) {

261

// Minimal output for CI environments

262

if (percentage === 0) console.log('Build started...');

263

if (percentage === 1) console.log('Build completed!');

264

} else {

265

// Rich progress bar for development

266

const width = 50;

267

const filled = Math.round(width * percentage);

268

const bar = '█'.repeat(filled) + '░'.repeat(width - filled);

269

process.stdout.write(`\r[${bar}] ${Math.round(percentage * 100)}% ${message}`);

270

if (percentage === 1) console.log(); // New line when complete

271

}

272

}

273

})

274

]

275

};

276

```

277

278

### File Watching System

279

280

Webpack's watching system monitors file changes and triggers rebuilds automatically, essential for development workflows.

281

282

```javascript { .api }

283

/**

284

* Manages file watching for automatic rebuilds during development

285

*/

286

class Watching {

287

/** Associated compiler instance */

288

compiler: Compiler;

289

290

/** Watch configuration options */

291

options: WatchOptions;

292

293

/** File system watcher instance */

294

watcher: any;

295

296

/**

297

* Close watching and cleanup resources

298

* @param callback - Completion callback

299

*/

300

close(callback?: () => void): void;

301

302

/**

303

* Invalidate current compilation and trigger rebuild

304

* @param filename - Optional filename that changed

305

*/

306

invalidate(filename?: string): void;

307

308

/**

309

* Suspend watching temporarily without closing

310

*/

311

suspend(): void;

312

313

/**

314

* Resume watching after suspension

315

*/

316

resume(): void;

317

}

318

319

/**

320

* Manages multiple watching instances for multi-compiler setups

321

*/

322

class MultiWatching {

323

/** Array of individual watching instances */

324

watchings: Watching[];

325

326

/** Multi-compiler instance */

327

compiler: MultiCompiler;

328

329

/**

330

* Close all watching instances

331

* @param callback - Completion callback

332

*/

333

close(callback?: () => void): void;

334

335

/**

336

* Invalidate all watching instances

337

*/

338

invalidate(): void;

339

340

/**

341

* Suspend all watching instances

342

*/

343

suspend(): void;

344

345

/**

346

* Resume all watching instances

347

*/

348

resume(): void;

349

}

350

351

/**

352

* Configuration options for file watching behavior

353

*/

354

interface WatchOptions {

355

/** Delay in milliseconds before rebuilding after change */

356

aggregateTimeout?: number;

357

/** Enable polling for file changes (useful for network drives) */

358

poll?: boolean | number;

359

/** Files, directories, or patterns to ignore */

360

ignored?: string | RegExp | string[] | ((path: string) => boolean);

361

/** Follow symbolic links */

362

followSymlinks?: boolean;

363

/** Use stdin to stop watching in CLI mode */

364

stdin?: boolean;

365

}

366

367

/**

368

* Plugin to ignore specific files during watch mode

369

* @param paths - Patterns of files to ignore during watching

370

*/

371

class WatchIgnorePlugin {

372

constructor(paths: Array<string | RegExp>);

373

}

374

```

375

376

**Usage Examples:**

377

378

```javascript

379

const webpack = require("webpack");

380

const path = require("path");

381

382

// Basic watching setup

383

const compiler = webpack(config);

384

const watching = compiler.watch({

385

aggregateTimeout: 300,

386

poll: 1000,

387

ignored: [

388

path.resolve(__dirname, 'node_modules'),

389

path.resolve(__dirname, 'dist')

390

]

391

}, (err, stats) => {

392

if (err || stats.hasErrors()) {

393

console.error(err || stats.toString());

394

return;

395

}

396

console.log('Rebuild completed!');

397

});

398

399

// Advanced watching configuration

400

module.exports = {

401

plugins: [

402

new webpack.WatchIgnorePlugin({

403

paths: [

404

/node_modules/,

405

/\.git/,

406

/\.DS_Store/,

407

path.resolve(__dirname, 'temp'),

408

path.resolve(__dirname, 'coverage')

409

]

410

})

411

],

412

watchOptions: {

413

aggregateTimeout: 200,

414

poll: false,

415

ignored: [

416

'**/node_modules',

417

'**/.git',

418

'**/temp/**'

419

],

420

followSymlinks: false

421

}

422

};

423

424

// Programmatic watching control

425

watching.invalidate(); // Trigger rebuild

426

watching.suspend(); // Pause watching

427

watching.resume(); // Resume watching

428

watching.close(() => {

429

console.log('Watching ended');

430

});

431

```

432

433

### Development Server Integration

434

435

Integration points and configuration for webpack development servers that provide live reloading, hot module replacement, and development middleware.

436

437

```javascript { .api }

438

/**

439

* DevTool options for debugging and development

440

*/

441

type DevTool =

442

| false

443

| 'eval'

444

| 'eval-cheap-source-map'

445

| 'eval-cheap-module-source-map'

446

| 'eval-source-map'

447

| 'cheap-source-map'

448

| 'cheap-module-source-map'

449

| 'source-map'

450

| 'inline-cheap-source-map'

451

| 'inline-cheap-module-source-map'

452

| 'inline-source-map'

453

| 'eval-nosources-cheap-source-map'

454

| 'eval-nosources-cheap-module-source-map'

455

| 'eval-nosources-source-map'

456

| 'inline-nosources-cheap-source-map'

457

| 'inline-nosources-cheap-module-source-map'

458

| 'inline-nosources-source-map'

459

| 'nosources-cheap-source-map'

460

| 'nosources-cheap-module-source-map'

461

| 'nosources-source-map'

462

| 'hidden-nosources-cheap-source-map'

463

| 'hidden-nosources-cheap-module-source-map'

464

| 'hidden-nosources-source-map'

465

| 'hidden-cheap-source-map'

466

| 'hidden-cheap-module-source-map'

467

| 'hidden-source-map';

468

469

/**

470

* Development mode specific optimizations and settings

471

*/

472

interface DevelopmentOptions {

473

/** Development tool for debugging */

474

devtool?: DevTool;

475

/** Enable development mode optimizations */

476

mode?: 'development';

477

/** Watch mode configuration */

478

watch?: boolean;

479

/** Watch options */

480

watchOptions?: WatchOptions;

481

/** Development server configuration */

482

devServer?: DevServerOptions;

483

/** Enable caching for development */

484

cache?: boolean | CacheOptions;

485

/** Source map exclude patterns */

486

infrastructureLogging?: {

487

level?: 'none' | 'error' | 'warn' | 'info' | 'log' | 'verbose';

488

debug?: string | RegExp | ((name: string) => boolean);

489

};

490

}

491

492

interface DevServerOptions {

493

/** Enable hot module replacement */

494

hot?: boolean | 'only';

495

/** Enable live reloading */

496

liveReload?: boolean;

497

/** Development server port */

498

port?: number | string;

499

/** Development server host */

500

host?: string;

501

/** Enable HTTPS */

502

https?: boolean | ServerOptions;

503

/** Static file serving configuration */

504

static?: string | StaticOptions | Array<string | StaticOptions>;

505

/** Proxy configuration */

506

proxy?: ProxyConfig;

507

/** History API fallback */

508

historyApiFallback?: boolean | HistoryApiFallbackOptions;

509

/** Overlay for compilation errors */

510

client?: {

511

overlay?: boolean | {

512

errors?: boolean;

513

warnings?: boolean;

514

};

515

progress?: boolean;

516

reconnect?: boolean | number;

517

};

518

}

519

```

520

521

**Usage Examples:**

522

523

```javascript

524

const webpack = require("webpack");

525

526

// Development configuration with optimal debugging

527

module.exports = {

528

mode: 'development',

529

devtool: 'eval-source-map',

530

entry: './src/index.js',

531

532

// Development server setup

533

devServer: {

534

hot: true,

535

liveReload: true,

536

port: 3000,

537

host: 'localhost',

538

static: {

539

directory: path.join(__dirname, 'public'),

540

publicPath: '/assets'

541

},

542

proxy: {

543

'/api': {

544

target: 'http://localhost:8080',

545

changeOrigin: true,

546

pathRewrite: {

547

'^/api': ''

548

}

549

}

550

},

551

historyApiFallback: {

552

rewrites: [

553

{ from: /^\/$/, to: '/views/landing.html' },

554

{ from: /^\/subpage/, to: '/views/subpage.html' },

555

{ from: /./, to: '/views/404.html' }

556

]

557

},

558

client: {

559

overlay: {

560

errors: true,

561

warnings: false

562

},

563

progress: true

564

}

565

},

566

567

// Optimized for development

568

cache: {

569

type: 'memory'

570

},

571

572

infrastructureLogging: {

573

level: 'info',

574

debug: ['webpack-dev-server']

575

},

576

577

plugins: [

578

new webpack.HotModuleReplacementPlugin(),

579

new webpack.ProgressPlugin({

580

activeModules: true,

581

modules: true,

582

handler: (percentage, message, ...args) => {

583

console.log(`${Math.round(percentage * 100)}% ${message} ${args.join(' ')}`);

584

}

585

})

586

]

587

};

588

589

// Multiple development configurations

590

const createDevConfig = (name, port) => ({

591

name,

592

mode: 'development',

593

devtool: 'eval-cheap-module-source-map',

594

entry: `./src/${name}/index.js`,

595

devServer: {

596

port,

597

hot: true,

598

allowedHosts: 'all'

599

},

600

plugins: [

601

new webpack.HotModuleReplacementPlugin(),

602

new webpack.DefinePlugin({

603

'process.env.SERVICE_NAME': JSON.stringify(name)

604

})

605

]

606

});

607

608

module.exports = [

609

createDevConfig('frontend', 3000),

610

createDevConfig('admin', 3001),

611

createDevConfig('mobile', 3002)

612

];

613

```

614

615

### Error Handling and Reporting

616

617

Comprehensive error handling and reporting capabilities for development debugging and build monitoring.

618

619

```javascript { .api }

620

/**

621

* Base class for webpack-specific errors with enhanced debugging information

622

*/

623

class WebpackError extends Error {

624

/** Error name */

625

name: string;

626

627

/** Error message */

628

message: string;

629

630

/** Module associated with error */

631

module?: Module;

632

633

/** Location information */

634

loc?: SourceLocation;

635

636

/** Error details */

637

details?: string;

638

639

/** Related file path */

640

file?: string;

641

642

/** Hide error from stats output */

643

hideStack?: boolean;

644

645

/** Error chunk */

646

chunk?: Chunk;

647

648

constructor(message?: string);

649

}

650

651

/**

652

* Compilation statistics with error and warning information

653

*/

654

class Stats {

655

/** Associated compilation */

656

compilation: Compilation;

657

658

/**

659

* Check if compilation has errors

660

* @returns True if errors exist

661

*/

662

hasErrors(): boolean;

663

664

/**

665

* Check if compilation has warnings

666

* @returns True if warnings exist

667

*/

668

hasWarnings(): boolean;

669

670

/**

671

* Get compilation errors

672

* @returns Array of error objects

673

*/

674

toJson(options?: StatsOptions): {

675

errors: StatsError[];

676

warnings: StatsError[];

677

errorDetails?: string;

678

// ... other stats properties

679

};

680

}

681

682

interface StatsError {

683

message: string;

684

formatted?: string;

685

moduleId?: string | number;

686

moduleIdentifier?: string;

687

moduleName?: string;

688

loc?: string;

689

file?: string;

690

details?: string;

691

}

692

693

interface SourceLocation {

694

line: number;

695

column?: number;

696

index?: number;

697

}

698

```

699

700

**Usage Examples:**

701

702

```javascript

703

const webpack = require("webpack");

704

705

// Enhanced error reporting

706

const compiler = webpack(config);

707

708

compiler.hooks.done.tap('ErrorReporter', (stats) => {

709

const info = stats.toJson({

710

all: false,

711

errors: true,

712

warnings: true,

713

errorDetails: true

714

});

715

716

if (stats.hasErrors()) {

717

console.error('Build failed with errors:');

718

info.errors.forEach((error, index) => {

719

console.error(`\nError ${index + 1}:`);

720

console.error(`File: ${error.file || 'unknown'}`);

721

console.error(`Module: ${error.moduleName || 'unknown'}`);

722

console.error(`Location: ${error.loc || 'unknown'}`);

723

console.error(`Message: ${error.message}`);

724

if (error.details) {

725

console.error(`Details: ${error.details}`);

726

}

727

});

728

}

729

730

if (stats.hasWarnings()) {

731

console.warn('Build completed with warnings:');

732

info.warnings.forEach((warning, index) => {

733

console.warn(`\nWarning ${index + 1}: ${warning.message}`);

734

});

735

}

736

});

737

738

// Custom error handling plugin

739

class ErrorHandlerPlugin {

740

apply(compiler) {

741

compiler.hooks.compilation.tap('ErrorHandler', (compilation) => {

742

compilation.hooks.buildModule.tap('ErrorHandler', (module) => {

743

console.log(`Building module: ${module.identifier()}`);

744

});

745

746

compilation.hooks.failedModule.tap('ErrorHandler', (module, error) => {

747

console.error(`Failed to build module: ${module.identifier()}`);

748

console.error(`Error: ${error.message}`);

749

750

// Enhanced error information

751

const enhancedError = new WebpackError(

752

`Module build failed: ${error.message}`

753

);

754

enhancedError.module = module;

755

enhancedError.file = module.resource;

756

enhancedError.details = error.stack;

757

758

compilation.errors.push(enhancedError);

759

});

760

});

761

}

762

}

763

764

module.exports = {

765

plugins: [

766

new ErrorHandlerPlugin()

767

],

768

769

stats: {

770

errors: true,

771

warnings: true,

772

errorDetails: true,

773

colors: true,

774

modules: false,

775

chunks: false

776

}

777

};

778

```

779

780

### Development Mode Optimizations

781

782

Optimizations and settings specifically designed for development builds to improve build speed and debugging experience.

783

784

```javascript { .api }

785

/**

786

* Development-specific optimization settings

787

*/

788

interface DevelopmentOptimization {

789

/** Disable minimization in development */

790

minimize?: false;

791

792

/** Fast module concatenation for development */

793

concatenateModules?: false;

794

795

/** Remove empty chunks */

796

removeEmptyChunks?: boolean;

797

798

/** Merge duplicate chunks */

799

mergeDuplicateChunks?: boolean;

800

801

/** Flag included chunks */

802

flagIncludedChunks?: false;

803

804

/** Remove available modules optimization */

805

removeAvailableModules?: false;

806

807

/** Provide bail out reasons for optimizations */

808

providedExports?: boolean;

809

810

/** Use exports analysis */

811

usedExports?: boolean;

812

813

/** Enable side effects analysis */

814

sideEffects?: boolean;

815

816

/** Node environment for process.env.NODE_ENV */

817

nodeEnv?: 'development';

818

}

819

820

/**

821

* Cache configuration optimized for development

822

*/

823

interface DevelopmentCache {

824

/** Cache type */

825

type: 'memory' | 'filesystem';

826

827

/** Cache name for multiple configurations */

828

name?: string;

829

830

/** Cache version */

831

version?: string;

832

833

/** Build dependencies for cache invalidation */

834

buildDependencies?: {

835

config?: string[];

836

defaultWebpack?: string[];

837

};

838

839

/** Memory cache specific options */

840

maxGenerations?: number;

841

cacheUnaffected?: boolean;

842

843

/** Filesystem cache options */

844

cacheDirectory?: string;

845

compression?: false | 'gzip' | 'brotli';

846

hashAlgorithm?: string;

847

store?: 'pack';

848

allowCollectingMemory?: boolean;

849

}

850

```

851

852

**Usage Examples:**

853

854

```javascript

855

const webpack = require("webpack");

856

const path = require("path");

857

858

// Optimized development configuration

859

module.exports = {

860

mode: 'development',

861

862

// Fast rebuilds with memory caching

863

cache: {

864

type: 'memory',

865

maxGenerations: 1,

866

cacheUnaffected: true

867

},

868

869

// Development optimizations

870

optimization: {

871

minimize: false,

872

removeAvailableModules: false,

873

removeEmptyChunks: false,

874

splitChunks: false,

875

concatenateModules: false,

876

flagIncludedChunks: false,

877

nodeEnv: 'development'

878

},

879

880

// Fast source maps

881

devtool: 'eval-cheap-module-source-map',

882

883

// Development-specific plugins

884

plugins: [

885

new webpack.HotModuleReplacementPlugin(),

886

new webpack.NoEmitOnErrorsPlugin(),

887

888

// Enhanced development environment

889

new webpack.DefinePlugin({

890

'process.env.NODE_ENV': JSON.stringify('development'),

891

'__DEV__': true,

892

'__PROD__': false

893

}),

894

895

new webpack.ProgressPlugin({

896

activeModules: false,

897

entries: true,

898

handler(percentage, message, ...args) {

899

// Only show major milestones to reduce noise

900

if (percentage === 0 || percentage === 1) {

901

console.log(`${Math.round(percentage * 100)}% ${message}`);

902

}

903

}

904

})

905

],

906

907

// Fast resolve for development

908

resolve: {

909

symlinks: false,

910

cacheWithContext: false

911

},

912

913

// Optimized file watching

914

watchOptions: {

915

ignored: [

916

path.resolve(__dirname, 'node_modules'),

917

'**/.git',

918

'**/dist',

919

'**/build'

920

],

921

aggregateTimeout: 100

922

},

923

924

// Development-friendly output

925

output: {

926

pathinfo: true,

927

filename: '[name].js',

928

chunkFilename: '[name].chunk.js'

929

}

930

};

931

932

// Multi-environment development setup

933

const createDevConfig = (env) => {

934

const isDevelopment = env === 'development';

935

const isTest = env === 'test';

936

937

return {

938

mode: isDevelopment ? 'development' : 'production',

939

940

cache: isDevelopment ? {

941

type: 'memory',

942

maxGenerations: 1

943

} : false,

944

945

devtool: isDevelopment

946

? 'eval-source-map'

947

: isTest

948

? 'inline-source-map'

949

: 'source-map',

950

951

plugins: [

952

...(isDevelopment ? [

953

new webpack.HotModuleReplacementPlugin(),

954

new webpack.ProgressPlugin()

955

] : []),

956

957

new webpack.DefinePlugin({

958

'process.env.NODE_ENV': JSON.stringify(env),

959

'__DEV__': isDevelopment,

960

'__TEST__': isTest

961

})

962

],

963

964

optimization: {

965

minimize: !isDevelopment && !isTest,

966

removeAvailableModules: !isDevelopment,

967

concatenateModules: !isDevelopment && !isTest

968

}

969

};

970

};

971

972

module.exports = (env, argv) => {

973

return createDevConfig(env.NODE_ENV || 'development');

974

};

975

```

976

977

## Common Types

978

979

```javascript { .api }

980

interface Compiler {

981

/** Webpack configuration options */

982

options: WebpackOptionsNormalized;

983

984

/** Compiler hooks for plugin integration */

985

hooks: CompilerHooks;

986

987

/** Start watching for file changes */

988

watch(

989

watchOptions: WatchOptions,

990

handler: (err: Error | null, stats?: Stats) => void

991

): Watching;

992

993

/** Run single build */

994

run(callback: (err: Error | null, stats?: Stats) => void): void;

995

996

/** Close compiler and cleanup */

997

close(callback: (err?: Error) => void): void;

998

}

999

1000

interface Compilation {

1001

/** Parent compiler */

1002

compiler: Compiler;

1003

1004

/** Compilation errors */

1005

errors: WebpackError[];

1006

1007

/** Compilation warnings */

1008

warnings: WebpackError[];

1009

1010

/** Generated assets */

1011

assets: Record<string, Asset>;

1012

1013

/** Get logger for compilation */

1014

getLogger(name: string): WebpackLogger;

1015

}

1016

1017

interface WebpackLogger {

1018

/** Log error message */

1019

error(...args: any[]): void;

1020

1021

/** Log warning message */

1022

warn(...args: any[]): void;

1023

1024

/** Log info message */

1025

info(...args: any[]): void;

1026

1027

/** Log debug message */

1028

log(...args: any[]): void;

1029

1030

/** Log debug message */

1031

debug(...args: any[]): void;

1032

1033

/** Log trace message */

1034

trace(...args: any[]): void;

1035

1036

/** Get child logger */

1037

getChildLogger(name: string): WebpackLogger;

1038

}

1039

1040

type WebpackPluginInstance = {

1041

apply(compiler: Compiler): void;

1042

};

1043

1044

interface CacheOptions {

1045

type: 'memory' | 'filesystem';

1046

name?: string;

1047

version?: string;

1048

cacheDirectory?: string;

1049

buildDependencies?: {

1050

config?: string[];

1051

defaultWebpack?: string[];

1052

};

1053

}

1054

```

1055

1056

## Development Workflow Patterns

1057

1058

### Hot Module Replacement Workflow

1059

1060

```javascript

1061

// webpack.config.js

1062

module.exports = {

1063

entry: './src/index.js',

1064

mode: 'development',

1065

devServer: {

1066

hot: true,

1067

port: 3000

1068

},

1069

plugins: [

1070

new webpack.HotModuleReplacementPlugin()

1071

]

1072

};

1073

1074

// src/index.js - HMR setup

1075

import { render } from './app';

1076

1077

render();

1078

1079

if (module.hot) {

1080

module.hot.accept('./app', () => {

1081

const { render } = require('./app');

1082

render();

1083

});

1084

}

1085

```

1086

1087

### Development Server with Proxy

1088

1089

```javascript

1090

module.exports = {

1091

devServer: {

1092

hot: true,

1093

proxy: {

1094

'/api': 'http://localhost:8080',

1095

'/ws': {

1096

target: 'ws://localhost:8080',

1097

ws: true

1098

}

1099

},

1100

historyApiFallback: true,

1101

client: {

1102

overlay: {

1103

errors: true,

1104

warnings: false

1105

}

1106

}

1107

}

1108

};

1109

```

1110

1111

### Multi-Configuration Development

1112

1113

```javascript

1114

module.exports = [

1115

// Client configuration

1116

{

1117

name: 'client',

1118

target: 'web',

1119

entry: './src/client/index.js',

1120

plugins: [

1121

new webpack.HotModuleReplacementPlugin()

1122

]

1123

},

1124

// Server configuration

1125

{

1126

name: 'server',

1127

target: 'node',

1128

entry: './src/server/index.js',

1129

plugins: [

1130

new webpack.WatchIgnorePlugin({

1131

paths: [/\.js$/, /\.d\.ts$/]

1132

})

1133

]

1134

}

1135

];

1136

```

1137

1138

The development tools ecosystem in webpack provides everything needed for efficient development workflows, from basic file watching to advanced hot module replacement and comprehensive debugging capabilities.