0
# Command Line Interface
1
2
The Parcel CLI provides a comprehensive command-line interface for building, serving, and debugging web applications. It offers commands for development server, file watching, production builds, and environment debugging.
3
4
## Installation
5
6
```bash
7
npm install -g parcel-bundler
8
```
9
10
Or use locally:
11
12
```bash
13
npx parcel <command>
14
```
15
16
## Capabilities
17
18
### Serve Command
19
20
Starts a development server with hot module replacement and file watching.
21
22
```bash { .api }
23
parcel serve [input...]
24
25
# Aliases (serve is the default command)
26
parcel [input...]
27
```
28
29
**Options:**
30
31
```bash { .api }
32
-p, --port <port> # Port to serve on (default: 1234)
33
--host <host> # Host to listen on (default: all interfaces)
34
--hmr-port <port> # Port for HMR websockets (default: random)
35
--hmr-hostname <hostname> # Hostname for HMR websockets
36
--https # Serve files over HTTPS
37
--cert <path> # Path to certificate for HTTPS
38
--key <path> # Path to private key for HTTPS
39
--open [browser] # Auto-open in browser (default browser)
40
--no-hmr # Disable hot module replacement
41
-d, --out-dir <path> # Output directory (default: 'dist')
42
-o, --out-file <filename> # Output filename for entry point
43
--public-url <url> # Public URL to serve on (default: '/')
44
--global <variable> # Expose module through global variable
45
--no-cache # Disable filesystem cache
46
--no-source-maps # Disable sourcemaps
47
--no-autoinstall # Disable autoinstall
48
-t, --target <target> # Runtime: 'node', 'browser', 'electron'
49
--bundle-node-modules # Force bundling node modules
50
--log-level <level> # Log level: 0-5 (0=silent, 5=debug)
51
--cache-dir <path> # Cache directory (default: '.cache')
52
```
53
54
**Usage Examples:**
55
56
```bash
57
# Basic development server
58
parcel index.html
59
parcel serve index.html
60
61
# Custom port and host
62
parcel index.html -p 3000 --host 0.0.0.0
63
64
# HTTPS with custom certificates
65
parcel index.html --https --cert ./cert.pem --key ./key.pem
66
67
# Multiple entry points
68
parcel index.html about.html --port 8080
69
70
# Target Node.js environment
71
parcel server.js --target node
72
73
# Disable HMR and caching
74
parcel index.html --no-hmr --no-cache
75
76
# Production-like build with serve
77
parcel index.html --no-source-maps --log-level 1
78
```
79
80
### Watch Command
81
82
Starts the bundler in watch mode without a development server.
83
84
```bash { .api }
85
parcel watch [input...]
86
```
87
88
**Options:**
89
90
```bash { .api }
91
-d, --out-dir <path> # Output directory (default: 'dist')
92
-o, --out-file <filename> # Output filename for entry point
93
--public-url <url> # Public URL (default: '/')
94
--global <variable> # Expose module through global variable
95
--hmr-port <port> # Port for HMR websockets
96
--hmr-hostname <hostname> # Hostname for HMR websockets
97
--https # Use HTTPS for HMR connections
98
--cert <path> # Path to certificate for HTTPS
99
--key <path> # Path to private key for HTTPS
100
--no-hmr # Disable hot module replacement
101
--no-cache # Disable filesystem cache
102
--no-source-maps # Disable sourcemaps
103
--no-autoinstall # Disable autoinstall
104
-t, --target <target> # Runtime: 'node', 'browser', 'electron'
105
--bundle-node-modules # Force bundling node modules
106
--log-level <level> # Log level: 0-5
107
--cache-dir <path> # Cache directory (default: '.cache')
108
```
109
110
**Usage Examples:**
111
112
```bash
113
# Watch mode for continuous building
114
parcel watch index.html
115
116
# Watch with custom output
117
parcel watch src/index.js -d build -o app.js
118
119
# Watch for Node.js target
120
parcel watch server.js --target node --out-dir lib
121
122
# Watch multiple files
123
parcel watch index.html admin.html --out-dir dist
124
125
# Watch with specific HMR configuration
126
parcel watch index.html --hmr-port 3001 --https
127
```
128
129
### Build Command
130
131
Bundles files for production with optimizations enabled.
132
133
```bash { .api }
134
parcel build [input...]
135
```
136
137
**Options:**
138
139
```bash { .api }
140
-d, --out-dir <path> # Output directory (default: 'dist')
141
-o, --out-file <filename> # Output filename for entry point
142
--public-url <url> # Public URL (default: '/')
143
--global <variable> # Expose module through global variable
144
--no-minify # Disable minification
145
--no-cache # Disable filesystem cache
146
--no-source-maps # Disable sourcemaps
147
--no-autoinstall # Disable autoinstall
148
--no-content-hash # Disable content hashing
149
--experimental-scope-hoisting # Enable scope hoisting/tree shaking
150
-t, --target <target> # Runtime: 'node', 'browser', 'electron'
151
--bundle-node-modules # Force bundling node modules
152
--detailed-report [depth] # Print detailed build report (default: 10)
153
--log-level <level> # Log level: 0-5
154
--cache-dir <path> # Cache directory (default: '.cache')
155
```
156
157
**Usage Examples:**
158
159
```bash
160
# Production build
161
parcel build index.html
162
163
# Build with custom output
164
parcel build src/index.js -d dist -o bundle.js
165
166
# Build for Node.js
167
parcel build server.js --target node --out-dir lib
168
169
# Build with scope hoisting
170
parcel build index.html --experimental-scope-hoisting
171
172
# Build without minification for debugging
173
parcel build index.html --no-minify --no-content-hash
174
175
# Build with detailed report
176
parcel build index.html --detailed-report 15
177
178
# Build multiple entry points
179
parcel build index.html admin.html --out-dir public
180
181
# Build library with global export
182
parcel build src/lib.js --global MyLibrary --target browser
183
```
184
185
### Info Command
186
187
Prints debugging information about the local environment.
188
189
```bash { .api }
190
parcel info
191
```
192
193
**Output Includes:**
194
195
- Operating system and CPU information
196
- Node.js, npm, and Yarn versions
197
- Browser versions (Chrome, Edge, Firefox, Safari)
198
- Local and global parcel-bundler installation details
199
200
**Usage Examples:**
201
202
```bash
203
# Get environment information
204
parcel info
205
206
# Example output:
207
# Environment Info:
208
# System:
209
# OS: macOS 10.15.7
210
# CPU: (8) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
211
# Binaries:
212
# Node: 14.17.0
213
# Yarn: 1.22.10
214
# npm: 6.14.13
215
# Browsers:
216
# Chrome: 91.0.4472.114
217
# Firefox: 89.0.1
218
# Safari: 14.1.1
219
# npmPackages:
220
# parcel-bundler: 1.12.5
221
```
222
223
### Help Command
224
225
Display help information for commands.
226
227
```bash { .api }
228
parcel help [command]
229
```
230
231
**Usage Examples:**
232
233
```bash
234
# General help
235
parcel help
236
parcel --help
237
238
# Command-specific help
239
parcel help serve
240
parcel help build
241
parcel help watch
242
243
# Show all available options for a command
244
parcel serve --help
245
parcel build --help
246
```
247
248
## Global Options
249
250
Options available for all commands:
251
252
```bash { .api }
253
-V, --version # Output version number
254
--help # Display help information
255
```
256
257
## Common Usage Patterns
258
259
**Development Workflow:**
260
261
```bash
262
# Start development
263
parcel index.html
264
265
# Watch mode without server
266
parcel watch index.html
267
268
# Production build
269
parcel build index.html
270
```
271
272
**Multi-Entry Applications:**
273
274
```bash
275
# Serve multiple pages
276
parcel serve index.html admin.html dashboard.html -p 3000
277
278
# Build SPA with multiple entry points
279
parcel build index.html --out-dir dist
280
```
281
282
**Library Development:**
283
284
```bash
285
# Development
286
parcel serve src/index.js --target browser --global MyLib
287
288
# Build for distribution
289
parcel build src/index.js --target browser --global MyLib --out-file lib.js
290
```
291
292
**Node.js Applications:**
293
294
```bash
295
# Development with watch
296
parcel watch server.js --target node --out-dir lib
297
298
# Production build
299
parcel build server.js --target node --out-dir dist --no-source-maps
300
```
301
302
**Custom Configuration:**
303
304
```bash
305
# Custom cache and output directories
306
parcel build index.html --cache-dir .parcel-cache --out-dir public
307
308
# Disable optimizations for debugging
309
parcel build index.html --no-minify --no-content-hash --log-level 4
310
311
# HTTPS development with custom certificates
312
parcel serve index.html --https --cert ./ssl/cert.pem --key ./ssl/key.pem
313
```
314
315
## Log Levels
316
317
The `--log-level` option controls output verbosity:
318
319
```bash { .api }
320
--log-level 0 # Silent (no output)
321
--log-level 1 # Errors only
322
--log-level 2 # Warnings and errors
323
--log-level 3 # Info, warnings, and errors (default)
324
--log-level 4 # Verbose output
325
--log-level 5 # Debug output (creates log file)
326
```
327
328
## Target Environments
329
330
The `--target` option specifies the runtime environment:
331
332
```bash { .api }
333
--target browser # Browser environment (default)
334
--target node # Node.js environment
335
--target electron # Electron application
336
```
337
338
Each target applies different optimizations and polyfills appropriate for the environment.