The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Context refers to a require or dynamic import() with an expression such as require('./locale/' + name + '.json').
When encountering such an expression, Rspack infers the directory ('./locale/') and a regular expression (/^.*\.json$/).
Since the name is not known at compile time, Rspack includes every file as module in the bundle.
The ContextReplacementPlugin allows you to override the inferred information. There are various ways to configure the plugin:
If the resource (directory) matches resourceRegExp, the plugin replaces the default resource, recursive flag or generated regular expression with newContentResource, newContentRecursive or newContextRegExp respectively.
If newContentResource is relative, it is resolved relative to the previous resource.
The moment/locale context is restricted to files matching /de|fr|hu/. Thus only those locales are included (see this issue for more information).
The newContentResource and newContentCreateContextMap parameters are also available:
These two parameters can be used together to redirect requests in a more targeted way. The newContentCreateContextMap allows you to map runtime requests to compile requests in the form of an object: