Skip to content

Commit

Permalink
docs(plugins): update NormalModuleReplacementPlugin example
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 25, 2024
1 parent 3a659c7 commit 1b59b2f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/content/plugins/normal-module-replacement-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ contributors:
- byzyk
- chenxsan
- askoufis
- snitin315
---

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 Down Expand Up @@ -46,15 +47,18 @@ module.exports = function (env) {
var appTarget = env.APP_TARGET || 'VERSION_A';
return {
plugins: [
new webpack.NormalModuleReplacementPlugin(
/-APP_TARGET$/,
function (resource) {
resource.request = resource.request.replace(
/-APP_TARGET/,
`-${appTarget}`
);
new webpack.NormalModuleReplacementPlugin(/-APP_TARGET$/, function (
resource
) {
resource.request = resource.request.replace(
/-APP_TARGET/,
`-${appTarget}`
);

if (resource.createData) {
resource.createData.request = resource.request;
}
),
}),
],
};
};
Expand Down

0 comments on commit 1b59b2f

Please sign in to comment.