浮声新志

webpack插件篇:ContextReplacementPlugin详解

用途说明

ContextReplacementPlugin (上下文替换插件)

If the resource (directory) matches resourceRegExp, the plugin replaces the default resource, recursive flag or regExp generated by parsing with newContentResource, newContentRecursive or newContextRegExp respectively. If newContentResource is relative, it is resolve relative to the previous resource. If newContentResource is a function, it is expected to overwrite the ‘request’ attribute of the supplied object.

webpack.config.js配置

1
2
3
4
5
new webpack.ContextReplacementPlugin(
resourceRegExp,
[newContentResource],
[newContentRecursive],
[newContentRegExp])

案例

1
2