Skip to content

Commit bedb85b

Browse files
authored
docs(api): update --define-process-env-node-env usage (#7273)
1 parent 489aeaa commit bedb85b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/content/api/cli.mdx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ You can use `--node-env` option to set `process.env.NODE_ENV`, which is availabl
620620
npx webpack --node-env production # process.env.NODE_ENV = 'production'
621621
```
622622

623-
T> The `mode` option would respect the `--node-env` option if you don't set it explicitly, i.e. `--node-env production` would set both `process.env.NODE_ENV` and `mode` to `'production'`
623+
W> This option is deprecated and removed in webpack-cli v5 in favor of the `--define-process-env-node-env` option.
624624

625625
### define-process-env-node-env
626626

@@ -632,7 +632,18 @@ An alias for [`--node-env`](/api/cli/#node-env) to set `process.env.NODE_ENV`:
632632
npx webpack --define-process-env-node-env production # process.env.NODE_ENV = 'production'
633633
```
634634

635-
T> The `mode` option would respect the `--define-process-env-node-env` option if you don't set it explicitly, i.e. `--define-process-env-node-env production` would set both `process.env.NODE_ENV` and `mode` to `'production'`
635+
When the `mode` option is not specified in the configuration, you can use the `--define-process-env-node-env` option to set the `mode`. For example, using `--define-process-env-node-env production` will set both `process.env.NODE_ENV` and `mode` to `'production'`.
636+
637+
If your configuration exports a function, the value of `--define-process-env-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 `--define-process-env-node-env` is accessible as `argv.nodeEnv` within the function and can be used accordingly.
638+
639+
```javascript
640+
module.exports = (env, argv) => {
641+
console.log(argv.defineProcessEnvNodeEnv); // 'production' if --define-process-env-node-env production is used
642+
return {
643+
// your configuration
644+
};
645+
};
646+
```
636647

637648
## Configuration Options
638649

0 commit comments

Comments
 (0)