Skip to content

Commit ad9bbf4

Browse files
committed
📝 more detail about production variables
1 parent ba6572d commit ad9bbf4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

part2/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ If we don't want to execute a portion of code in production we can use the handy
266266
[DefinePlugin](https://github.com/webpack/docs/wiki/list-of-plugins#defineplugin).
267267

268268
The plugin lets us create a global constant for our entire bundle, which we could name anything,
269-
such as `DONT_USE_IN_PRODUCTION: true`, but more practically, a popular choice that looks a bit more
270-
familiar is `process.env.NODE_ENV: JSON.stringify('production')`. Why `JSON.stringify`? Because
271-
according to the docs:
269+
such as `DONT_USE_IN_PRODUCTION: true`, but more practically, it's a much better choice to use
270+
`process.env.NODE_ENV: JSON.stringify('production')`. This is because many programs recognize and
271+
use `process.env.NODE_ENV` for additional features and optimization of your code.
272+
273+
Why `JSON.stringify`? Because according to the docs:
272274

273275
> If the value is a string it will be used as a code fragment.
274276
@@ -302,7 +304,16 @@ if (process.env.NODE_ENV !== 'production') {
302304
}
303305
```
304306

305-
I touched upon a real world usage of this in an isolated section of part 1 [here](https://github.com/AriaFallah/WebpackTutorial/tree/master/part1/html-reload).
307+
In our current project we could say to exclude the hot reloading if it's in production:
308+
309+
```javascript
310+
// Accept hot module reloading during development
311+
if (process.env.NODE_ENV !== 'production') {
312+
if (module.hot) {
313+
module.hot.accept()
314+
}
315+
}
316+
```
306317

307318
#### Babel
308319

0 commit comments

Comments
 (0)