You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For proper usage and easier distribution of this configuration, webpack can be configured with `webpack.config.js`. Any parameters sent to the CLI will map to a corresponding parameter in the configuration file.
34
34
35
+
## ⚡ Quick Start
36
+
37
+
Most commonly used commands:
38
+
39
+
-**Production build**
40
+
41
+
```bash
42
+
npx webpack --mode production
43
+
```
44
+
45
+
-**Start development server**
46
+
47
+
```bash
48
+
npx webpack serve --open
49
+
```
50
+
51
+
-**Watch for file changes**
52
+
53
+
```bash
54
+
npx webpack --watch
55
+
```
56
+
57
+
-**Run with config file**
58
+
59
+
```bash
60
+
npx webpack --config webpack.config.js
61
+
```
62
+
63
+
💡 Tip: Use `serve` during development instead of `watch` for live reload.
64
+
35
65
Read the [installation guide](/guides/installation) if you don't already have webpack and CLI installed.
|[`build`](#build)|`build\|bundle\|b [entries...] [options]`| Run webpack (default command, can be omitted). |
48
-
|[`configtest`](#configtest)|`configtest\|t [config-path]`| Validate a webpack configuration. |
49
-
|[`help`](#help)|`help\|h [command] [option]`| Display help for commands and options. |
50
-
|[`info`](#info)|`info\|i [options]`| Outputs information about your system. |
51
-
|[`serve`](#serve)|`serve\|server\|s [options]`| Run the `webpack-dev-server`. |
52
-
|[`version`](#version)|`version\|v [commands...]`| Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and other packages. |
53
-
|[`watch`](#watch)|`watch\|w [entries...] [options]`| Run webpack and watch for files changes. |
109
+
## When should I use each command?
110
+
111
+
-**build** → Create a production-ready bundle
112
+
-**serve** → Run development server with live reload
113
+
-**watch** → Rebuild automatically without dev server
114
+
-**configtest** → Validate configuration file
115
+
-**info** → Debug environment issues
116
+
117
+
## Common Use Cases
118
+
119
+
### Build for production
120
+
121
+
```bash
122
+
npx webpack --mode production
123
+
```
124
+
125
+
### Development with live reload
126
+
127
+
```bash
128
+
npx webpack serve --mode development --open
129
+
```
130
+
131
+
### Debug configuration
132
+
133
+
````bash
134
+
npx webpack configtest
135
+
```|
54
136
55
137
### Build
56
138
57
139
Run webpack (default command, can be omitted).
58
140
59
141
```bash
60
142
npx webpack build [options]
61
-
```
143
+
````
62
144
63
145
**example**
64
146
@@ -253,9 +335,56 @@ npx webpack watch [options]
253
335
npx webpack watch --mode development
254
336
```
255
337
338
+
---
339
+
256
340
## Flags
257
341
258
-
By default webpack ships with the following flags:
W> The `--entry-reset` option is required to replace the existing [entry](/configuration/entry-context/#entry) option, without it the `--entry` option will add another entry to the existing entries.
353
506
507
+
### Example: Before vs After
508
+
509
+
Without `--entry-reset`:
510
+
511
+
```bash
512
+
npx webpack --entry ./new.js
513
+
```
514
+
515
+
Adds to existing entries.
516
+
517
+
With `--entry-reset`:
518
+
519
+
```bash
520
+
npx webpack --entry-reset ./new.js
521
+
```
522
+
523
+
Replaces all previous entries.
524
+
354
525
T> Use `webpack [command] --entry-reset [entries...] [option]` syntax because some options can accept multiple values so `webpack --target node ./entry.js` means `target: ['node', './entry.js']`
355
526
356
527
#### output-path
@@ -407,9 +578,7 @@ This is the lookup priority in increasing order
407
578
> example - config file lookup will be in order of webpack.config.js > .webpack/webpack.config.js > .webpack/webpackfile.js
When the `mode` option is not specified in the configuration, you can use the `--config-node-env` option to set the `mode`. For example, using `--config-node-env production` will set both `process.env.NODE_ENV` and `mode` to `'production'`.
621
798
622
-
If your configuration exports a function, the value of `--config-node-env` is assigned to mode after the function returns. This means that `mode` will not be available in the function arguments (`env` and `argv`). However, the value of `--config-node-env` is accessible as `argv.nodeEnv` within the function and can be used accordingly.
799
+
If your configuration exports a function, the value of `--config-node-env` is assigned to `mode` after the function returns. This means that `mode` will not be available in the function arguments (`env` and `argv`). However, the value of `--config-node-env` is accessible as `argv.nodeEnv` within the function and can be used accordingly.
0 commit comments