[英]Choose for which files to provide the selection module webpack.ProvidePlugin
Is it possible that in my config I have chosen to serve the react package for specific files with the.jsx extension.是否有可能在我的配置中,我选择为带有 .jsx 扩展名的特定文件提供反应 package。
Now I have react imported for both.js and.jsx, but can I restrict it only for.jsx files现在我已经为 .js 和 .jsx 都导入了反应,但我可以只为 .jsx 文件限制它吗
new webpack.ProvidePlugin({
"React": "react",
}),
This is currently not possible using the webpack ProviderPlugin.目前使用 webpack ProviderPlugin 是不可能的。
As a temporary solution, you could modify the ProviderPlugin in node_modules/webpack/lib/ProviderPlugin.js
and add the following code below lines 56 and 47:作为临时解决方案,您可以修改node_modules/webpack/lib/ProviderPlugin.js
中的 ProviderPlugin,并在第 56 行和第 47 行下方添加以下代码:
parser.hooks.expression.for(name).tap("ProvidePlugin", expr => {
if (name === 'React' && !parser.state.current.resource.endsWith('.jsx')) {
return true;
}
// ...
});
You could even fork the plugin and publish it under your NPM account as a modified version.您甚至可以分叉插件并将其作为修改版本发布在您的 NPM 帐户下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.