The configuration above will replace every instance of process.env.NODE_ENV with "production" and __buildDate__ with the result of the given function in any file included in the build.
Note: Values must be either primitives (e.g. string, number) or function that returns a string. For complex values, use JSON.stringify. To replace a target with a value that will be evaluated as a string, set the value to a quoted string (e.g. "test") or use JSON.stringify to preprocess the target string safely.
Typically, @rollup/plugin-replace should be placed in pluginsbefore other plugins so that they may apply optimizations, such as dead code removal.
Options
In addition to the properties and values specified for replacement, users may also specify the options below.
Specifies the boundaries around which strings will be replaced. By default, delimiters match JavaScript identifier boundaries and also prevent replacements of instances with nested access. See Word Boundaries below for more information.
For example, if you pass typeof window in values to-be-replaced, then you could expect the following scenarios:
typeof windowwill be replaced
typeof window.documentwill not be replaced due to the (?!\.) boundary
typeof windowSmthwill not be replaced due to identifier boundaries
Delimiters will be used to build a Regexp. To match special characters (any of .*+?^${}()|[]\), be sure to escape them.
objectGuards
Type: Boolean
Default: false
When replacing dot-separated object properties like process.env.NODE_ENV, will also replace typeof process object guard
checks against the objects with the string "object".
By default, values will only match if they are surrounded by word boundaries that respect JavaScript's rules for valid identifiers (including $ and _ as valid identifier characters).