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
Copy file name to clipboardExpand all lines: content/plugins/define-plugin.md
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,17 @@ title: DefinePlugin
6
6
newwebpack.DefinePlugin(definitions)
7
7
```
8
8
9
-
The `DefinePlugin` allows you to create global constants which can be configured at **compile** time. This can be very useful for allowing different behaviour between development builds and release builds. For example, you might use a global constant to determine whether logging takes place; perhaps you perform logging in your development build but not in the release build. That's the sort of scenario the `DefinePlugin` facilitates.
9
+
The `DefinePlugin` allows you to create global constants which can be configured at **compile** time. This can be very useful for allowing different behaviour between development builds and release builds. For example, you might use a global constant to determine whether logging takes place; perhaps you perform logging in your development build but not in the release build. That's the sort of scenario the `DefinePlugin` facilitates.
10
10
11
-
Example:
11
+
**Example:**
12
12
13
13
```javascript
14
14
newwebpack.DefinePlugin({
15
-
PRODUCTION:JSON.stringify(true),
16
-
VERSION:JSON.stringify("5fa3b9"),
17
-
BROWSER_SUPPORTS_HTML5:true,
18
-
TWO:"1+1",
19
-
"typeof window":JSON.stringify("object")
15
+
PRODUCTION:JSON.stringify(true),
16
+
VERSION:JSON.stringify("5fa3b9"),
17
+
BROWSER_SUPPORTS_HTML5:true,
18
+
TWO:"1+1",
19
+
"typeof window":JSON.stringify("object")
20
20
})
21
21
```
22
22
@@ -36,21 +36,25 @@ Each key passed into `DefinePlugin` is an identifier or multiple identifiers joi
36
36
37
37
The values will be inlined into the code which allows a minification pass to remove the redundant conditional.
38
38
39
-
Example:
39
+
**Example:**
40
40
41
41
```javascript
42
-
if (!PRODUCTION)
43
-
console.log('Debug info')
44
-
if (PRODUCTION)
45
-
console.log('Production log')
42
+
if (!PRODUCTION) {
43
+
console.log('Debug info')
44
+
}
45
+
if (PRODUCTION) {
46
+
console.log('Production log')
47
+
}
46
48
`````
47
49
After passing through webpack with no minification results in:
0 commit comments