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: src/content/plugins/define-plugin.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ contributors:
11
11
12
12
The `DefinePlugin` allows you to create global constants which can be configured at __compile__ time. This can be useful for allowing different behavior between development builds and production builds. If you perform logging in your development build but not in the production build you might use a global constant to determine whether logging takes place. That's where `DefinePlugin` shines, set it and forget it rules for development and production builds.
13
13
14
-
```javascript
14
+
```javascript
15
15
newwebpack.DefinePlugin({
16
16
// Definitions...
17
17
});
@@ -29,7 +29,7 @@ Each key passed into `DefinePlugin` is an identifier or multiple identifiers joi
29
29
30
30
The values will be inlined into the code allowing a minification pass to remove the redundant conditional.
31
31
32
-
```javascript
32
+
```javascript
33
33
newwebpack.DefinePlugin({
34
34
PRODUCTION:JSON.stringify(true),
35
35
VERSION:JSON.stringify('5fa3b9'),
@@ -40,7 +40,7 @@ new webpack.DefinePlugin({
40
40
});
41
41
```
42
42
43
-
```javascript
43
+
```javascript
44
44
console.log('Running App version '+VERSION);
45
45
if(!BROWSER_SUPPORTS_HTML5) require('html5shiv');
46
46
```
@@ -50,9 +50,7 @@ W> When defining values for `process` prefer `'process.env.NODE_ENV': JSON.strin
50
50
51
51
T> Note that because the plugin does a direct text replacement, the value given to it must include __actual quotes__ inside of the string itself. Typically, this is done either with alternate quotes, such as `'"production"'`, or by using `JSON.stringify('production')`.
52
52
53
-
__index.js__
54
-
55
-
```javascript
53
+
```javascript
56
54
if (!PRODUCTION) {
57
55
console.log('Debug info');
58
56
}
@@ -64,7 +62,7 @@ if (PRODUCTION) {
64
62
65
63
After passing through webpack with no minification results in:
It is possible to define variables with values that rely on files and will be re-evaluated when such files change in the file system. This means webpack will rebuild when such watched files change.
110
108
111
-
```javascript
109
+
Arguments:
110
+
111
+
- The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function` that should return the value to be assigned to the definition.
112
+
- The second argument is an array of file paths to watch for. Pass `true` instead of `[string]` here to flag the module as uncacheable.
The first argument to `runtimeValue` is a `function` that returns the value to be assigned and the second argument is an array of `fileDependencies` (what files to be watch for).
121
-
122
-
In the previous example, the value of `BUILD_AT` would be the time at which the file passed as `fileDep` was last updated in the file system.
123
-
124
-
T> Passing `true` as second argument instead of `fileDependencies` will flag the module as uncacheable.
122
+
The value of `BUILT_AT` would be the time at which the `'sample.txt'` was last updated in the file system, e.g. `1597953013291`.
0 commit comments