Skip to content

Commit 53479ee

Browse files
anshumanvchenxsan
andauthored
docs(plugins): New DefinePlugin options (#4865)
* New DefinePlugin options * docs: improve defineplugin * docs: improve defineplugin * docs: improve defineplugin * docs: improve defineplugin * Update Co-authored-by: Sam Chen <[email protected]>
1 parent db514db commit 53479ee

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/content/plugins/define-plugin.md renamed to src/content/plugins/define-plugin.mdx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,28 @@ new webpack.DefinePlugin({
9797

9898
## Runtime values via `runtimeValue`
9999

100-
`function (getterFunction, [string]) => getterFunction()`
100+
`function (getterFunction, [string] | true | object) => getterFunction()`
101101

102102
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.
103103

104-
Arguments:
104+
There're two arguments for `webpack.DefinePlugin.runtimeValue` function:
105105

106-
- The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function` that should return the value to be assigned to the definition.
107-
- The second argument is an array of file paths to watch for. Pass `true` instead of `[string]` here to flag the module as uncacheable.
106+
- The first argument is a `function(module, key, version)` that should return the value to be assigned to the definition.
107+
- The second argument could either be an array of file paths to watch for or a `true` to flag the module as uncacheable. Since 5.26.0, it can also take an object argument with the following properties:
108+
109+
- `fileDependencies?: string[]` A list of files the function depends on.
110+
- `contextDependencies?: string[]` A list of directories the function depends on.
111+
- `missingDependencies?: string[]` A list of not existing files the function depends on.
112+
- `buildDependencies?: string[]` A list of build dependencies the function depends on.
113+
- `version?: string | () => string` A version of the function.
108114

109115
```javascript
110116
const fileDep = path.resolve(__dirname, 'sample.txt');
111117

112118
new webpack.DefinePlugin({
113-
BUILT_AT: webpack.DefinePlugin.runtimeValue(Date.now, [fileDep]),
119+
BUILT_AT: webpack.DefinePlugin.runtimeValue(Date.now, {
120+
fileDependencies: [fileDep],
121+
}),
114122
});
115123
```
116124

0 commit comments

Comments
 (0)