Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(plugins): add a note for resourceRegExp #5450

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/content/plugins/normal-module-replacement-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ group: webpack
contributors:
- gonzoyumo
- byzyk
- chenxsan
---

The `NormalModuleReplacementPlugin` allows you to replace resources that match `resourceRegExp` with `newResource`. If `newResource` is relative, it is resolved relative to the previous resource. If `newResource` is a function, it is expected to overwrite the request attribute of the supplied resource.
Expand All @@ -14,6 +15,8 @@ This can be useful for allowing different behaviour between builds.
new webpack.NormalModuleReplacementPlugin(resourceRegExp, newResource);
```

Note that the `resourceRegExp` is tested against the request you write in your code, not the resolved resource. For instance, `'./sum'` will be used to test instead of `'./sum.js'` when you have code `import sum from './sum'`.

## Basic Example

Replace a specific module when building for a [development environment](/guides/production).
Expand Down