From e8fb8fcd8280efe0ca976188ac39df597e8be3dc Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Wed, 14 Apr 2021 00:58:50 +0530 Subject: [PATCH 1/6] New DefinePlugin options --- src/content/plugins/define-plugin.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/content/plugins/define-plugin.md b/src/content/plugins/define-plugin.md index ec85beff077e..76ed874f43ef 100644 --- a/src/content/plugins/define-plugin.md +++ b/src/content/plugins/define-plugin.md @@ -104,13 +104,22 @@ It is possible to define variables with values that rely on files and will be re Arguments: - The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function` that should return the value to be assigned to the definition. -- 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 second argument is an options object argument with the following properties + - `options.fileDependencies: string[]` list of files the function depends on + - `options.contextDependencies: string[]` list of directories the function depends on + - `options.missingDependencies: string[]` list of not existing files the function depends on + - `options.buildDependencies: string[]` list of build dependencies the function depends on + - `options.version: string | () => string` version of the function + +W> The constant options of the DefinePlugin do not have to be covered by build dependencies but for the `DefinePlugin.runtimeValue` generator function build dependencies need to be used. ```javascript const fileDep = path.resolve(__dirname, 'sample.txt'); new webpack.DefinePlugin({ - BUILT_AT: webpack.DefinePlugin.runtimeValue(Date.now, [fileDep]), + BUILT_AT: webpack.DefinePlugin.runtimeValue(Date.now, { + fileDependencies: [fileDep], + }), }); ``` From 2ec4c074a8bf463a7f3262a5356d1154d30a62fd Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Wed, 14 Apr 2021 22:14:43 +0530 Subject: [PATCH 2/6] docs: improve defineplugin --- .../{define-plugin.md => define-plugin.mdx} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/content/plugins/{define-plugin.md => define-plugin.mdx} (82%) diff --git a/src/content/plugins/define-plugin.md b/src/content/plugins/define-plugin.mdx similarity index 82% rename from src/content/plugins/define-plugin.md rename to src/content/plugins/define-plugin.mdx index 76ed874f43ef..e1142dd46f3b 100644 --- a/src/content/plugins/define-plugin.md +++ b/src/content/plugins/define-plugin.mdx @@ -103,15 +103,15 @@ It is possible to define variables with values that rely on files and will be re Arguments: -- The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function` that should return the value to be assigned to the definition. -- The second argument is an options object argument with the following properties - - `options.fileDependencies: string[]` list of files the function depends on - - `options.contextDependencies: string[]` list of directories the function depends on - - `options.missingDependencies: string[]` list of not existing files the function depends on - - `options.buildDependencies: string[]` list of build dependencies the function depends on - - `options.version: string | () => string` version of the function - -W> The constant options of the DefinePlugin do not have to be covered by build dependencies but for the `DefinePlugin.runtimeValue` generator function build dependencies need to be used. +- The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function(module, key, version)` that should return the value to be assigned to the definition. +- 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 second argument can also take an options object argument + with the following properties - `fileDependencies?: string[]` A list of files the + function depends on. - `contextDependencies?: string[]` A list of directories the + function depends on. - `missingDependencies?: string[]` A list of not existing + files the function depends on. - `buildDependencies?: string[]` A list of build + dependencies the function depends on. - `version?: string | () => string` A version + of the function. ```javascript const fileDep = path.resolve(__dirname, 'sample.txt'); From 5fc6c14d5ba4366fac8535be3434db750f16ac1e Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 15 Apr 2021 10:12:55 +0530 Subject: [PATCH 3/6] docs: improve defineplugin --- src/content/plugins/define-plugin.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/plugins/define-plugin.mdx b/src/content/plugins/define-plugin.mdx index e1142dd46f3b..49d46e170bed 100644 --- a/src/content/plugins/define-plugin.mdx +++ b/src/content/plugins/define-plugin.mdx @@ -106,9 +106,9 @@ Arguments: - The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function(module, key, version)` that should return the value to be assigned to the definition. - 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 second argument can also take an options object argument - with the following properties - `fileDependencies?: string[]` A list of files the - function depends on. - `contextDependencies?: string[]` A list of directories the - function depends on. - `missingDependencies?: string[]` A list of not existing + with the following properties - - `fileDependencies?: string[]` A list of files + the function depends on. - `contextDependencies?: string[]` A list of directories + the function depends on. - `missingDependencies?: string[]` A list of not existing files the function depends on. - `buildDependencies?: string[]` A list of build dependencies the function depends on. - `version?: string | () => string` A version of the function. From 1ab5cc06448406d7eb01a8383d806fc5c7e64c89 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 15 Apr 2021 10:13:52 +0530 Subject: [PATCH 4/6] docs: improve defineplugin --- src/content/plugins/define-plugin.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/content/plugins/define-plugin.mdx b/src/content/plugins/define-plugin.mdx index 49d46e170bed..d64fbde5796b 100644 --- a/src/content/plugins/define-plugin.mdx +++ b/src/content/plugins/define-plugin.mdx @@ -106,12 +106,12 @@ Arguments: - The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function(module, key, version)` that should return the value to be assigned to the definition. - 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 second argument can also take an options object argument - with the following properties - - `fileDependencies?: string[]` A list of files - the function depends on. - `contextDependencies?: string[]` A list of directories - the function depends on. - `missingDependencies?: string[]` A list of not existing - files the function depends on. - `buildDependencies?: string[]` A list of build - dependencies the function depends on. - `version?: string | () => string` A version - of the function. + with the following properties - + - `fileDependencies?: string[]` A list of files the function depends on. + - `contextDependencies?: string[]` A list of directories the function depends on. + - `missingDependencies?: string[]` A list of not existing files the function depends on. + - `buildDependencies?: string[]` A list of build dependencies the function depends on. + - `version?: string | () => string` A version of the function. ```javascript const fileDep = path.resolve(__dirname, 'sample.txt'); From 9b46a2489a799cbc3462d89177e3482eeb232d4c Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 15 Apr 2021 10:25:08 +0530 Subject: [PATCH 5/6] docs: improve defineplugin --- src/content/plugins/define-plugin.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/content/plugins/define-plugin.mdx b/src/content/plugins/define-plugin.mdx index d64fbde5796b..cf89fff24ea7 100644 --- a/src/content/plugins/define-plugin.mdx +++ b/src/content/plugins/define-plugin.mdx @@ -106,7 +106,8 @@ Arguments: - The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function(module, key, version)` that should return the value to be assigned to the definition. - 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 second argument can also take an options object argument - with the following properties - + with the following properties: + - `fileDependencies?: string[]` A list of files the function depends on. - `contextDependencies?: string[]` A list of directories the function depends on. - `missingDependencies?: string[]` A list of not existing files the function depends on. From b321174ef8e439fd4e4ddfe7cfa2047f1eb5300d Mon Sep 17 00:00:00 2001 From: Sam Chen Date: Fri, 16 Apr 2021 19:21:48 +0800 Subject: [PATCH 6/6] Update --- src/content/plugins/define-plugin.mdx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/content/plugins/define-plugin.mdx b/src/content/plugins/define-plugin.mdx index cf89fff24ea7..9873acf1af30 100644 --- a/src/content/plugins/define-plugin.mdx +++ b/src/content/plugins/define-plugin.mdx @@ -97,16 +97,14 @@ new webpack.DefinePlugin({ ## Runtime values via `runtimeValue` -`function (getterFunction, [string]) => getterFunction()` +`function (getterFunction, [string] | true | object) => getterFunction()` 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. -Arguments: +There're two arguments for `webpack.DefinePlugin.runtimeValue` function: -- The first argument of the `webpack.DefinePlugin.runtimeValue` is a `function(module, key, version)` that should return the value to be assigned to the definition. -- 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 second argument can also take an options object argument - with the following properties: +- The first argument is a `function(module, key, version)` that should return the value to be assigned to the definition. +- 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: - `fileDependencies?: string[]` A list of files the function depends on. - `contextDependencies?: string[]` A list of directories the function depends on.