0
# CLI Interface
1
2
Webpack CLI provides a comprehensive command-line interface for webpack operations including building, serving, configuration testing, and system information.
3
4
## Capabilities
5
6
### Core Commands
7
8
Main webpack CLI commands for different operations.
9
10
```bash { .api }
11
# Build command (default)
12
webpack-cli [entry] [options]
13
14
# Development server
15
webpack-cli serve [options]
16
17
# System and configuration information
18
webpack-cli info [options]
19
20
# Test configuration
21
webpack-cli configtest [config-path]
22
23
# Help system
24
webpack-cli help [command]
25
webpack-cli --help
26
27
# Version information
28
webpack-cli --version
29
```
30
31
### Build Command (Default)
32
33
The default command that runs webpack compilation.
34
35
```bash { .api }
36
webpack-cli [entry] [options]
37
38
# Examples:
39
webpack-cli # Use default config
40
webpack-cli ./src/index.js # Specify entry point
41
webpack-cli --mode production # Set mode
42
webpack-cli --config webpack.prod.js # Custom config file
43
```
44
45
**Common Build Options:**
46
47
```bash { .api }
48
# Configuration
49
--config <path> # Configuration file path
50
--config-name <name> # Named configuration
51
--merge # Merge configurations
52
53
# Entry and Output
54
--entry <path> # Entry point
55
--output-path <path> # Output directory
56
--output-filename <name> # Output filename pattern
57
--output-public-path <path> # Public path for assets
58
59
# Mode and Environment
60
--mode <mode> # Development or production mode
61
--env <env> # Environment variables for config
62
63
# Development Options
64
--watch # Watch for file changes
65
--watch-options-aggregated-timeout <ms> # Watch debounce timeout
66
--watch-options-ignored <pattern> # Ignore patterns for watching
67
68
# Progress and Output
69
--progress # Show progress
70
--json # Output stats as JSON
71
--stats <preset> # Stats output level
72
--analyze # Run bundle analyzer
73
```
74
75
### Serve Command
76
77
Development server integration with webpack-dev-server.
78
79
```bash { .api }
80
webpack-cli serve [options]
81
82
# Examples:
83
webpack-cli serve # Start dev server
84
webpack-cli serve --port 3000 # Custom port
85
webpack-cli serve --host 0.0.0.0 # Custom host
86
webpack-cli serve --open # Open browser
87
```
88
89
**Serve Options:**
90
91
```bash { .api }
92
# Server Configuration
93
--host <host> # Dev server host
94
--port <port> # Dev server port
95
--https # Enable HTTPS
96
--open [target] # Open browser
97
98
# Hot Reloading
99
--hot # Enable hot module replacement
100
--live-reload # Enable live reload
101
102
# Static Files
103
--static <path> # Serve static files from path
104
--static-public-path <path> # Public path for static files
105
```
106
107
### Info Command
108
109
System and configuration information display.
110
111
```bash { .api }
112
webpack-cli info [options]
113
114
# Examples:
115
webpack-cli info # Basic system info
116
webpack-cli info --additional-package react # Include package info
117
webpack-cli info --output json # JSON output format
118
```
119
120
**Info Options:**
121
122
```bash { .api }
123
--output <format> # Output format (json, markdown)
124
--additional-package <name> # Include additional package info
125
```
126
127
### Configtest Command
128
129
Validate webpack configuration files.
130
131
```bash { .api }
132
webpack-cli configtest [config-path]
133
134
# Examples:
135
webpack-cli configtest # Test default config
136
webpack-cli configtest webpack.prod.js # Test specific config
137
webpack-cli configtest --config-name prod # Test named config
138
```
139
140
### Global Options
141
142
Options available across all commands.
143
144
```bash { .api }
145
# Help and Version
146
--help # Show help
147
--version # Show version
148
149
# Verbosity
150
--silent # Suppress output
151
--verbose # Verbose output
152
153
# Colors
154
--color # Force color output
155
--no-color # Disable color output
156
```
157
158
### Configuration Options
159
160
Webpack configuration options available via CLI flags.
161
162
```bash { .api }
163
# Optimization
164
--optimization-minimize # Enable minification
165
--optimization-concatenate-modules # Enable module concatenation
166
--optimization-split-chunks # Enable chunk splitting
167
168
# Performance
169
--performance-hints <value> # Performance hints level
170
--performance-max-entrypoint-size <size> # Max entrypoint size
171
--performance-max-asset-size <size> # Max asset size
172
173
# DevTool
174
--devtool <type> # Source map type
175
176
# Target
177
--target <target> # Compilation target
178
179
# Resolve
180
--resolve-alias-<key> <value> # Add resolve alias
181
--resolve-extensions <ext> # Resolve extensions
182
```
183
184
### Exit Codes
185
186
CLI exit codes for different scenarios.
187
188
```bash { .api }
189
# Exit codes:
190
# 0 - Success
191
# 1 - Webpack compilation errors
192
# 2 - Configuration/CLI errors
193
```
194
195
**Usage Examples:**
196
197
```bash
198
# Basic build
199
webpack-cli
200
201
# Production build with custom config
202
webpack-cli --mode production --config webpack.prod.js
203
204
# Watch mode with progress
205
webpack-cli --watch --progress
206
207
# Development server with hot reload
208
webpack-cli serve --hot --open
209
210
# Bundle analysis
211
webpack-cli --analyze --mode production
212
213
# Configuration validation
214
webpack-cli configtest webpack.prod.js
215
216
# System information
217
webpack-cli info --output json
218
```