[英]How to shim npm package dependency in browserify?
So I have a React project, in which I'm actually deploying with react-lite as the footprint is much smaller. 所以我有一个作出反应的项目,其中我实际上有反应,精简版部署的足迹要小得多。 I'd like to use react-nouislider , but in it's package.json, I've found this:
我想使用react-nouislider ,但是在package.json中,我发现了这一点:
"peerDependencies": {
"react": "^0.14.0"
}
What this means is that whenever I require react-nouislider, it pulls in React instead of react-lite. 这意味着每当我需要react-nouislider时,它都会拉入React而不是react-lite。 How do I shim dependencies of an npm package from my top-level package.json?
如何从我的顶级package.json中填充npm包的依赖项?
This is how I'm shimming react-lite in: 这就是我在反应中的反应:
"browser": {
"react": "react-lite"
}
And I tried this, but it didn't work: 我尝试了一下,但是没有用:
"browserify-shim":{
"react-nouislider": {
"depends": "react-lite"
}
}
How is it possible to shim a dependency of a package itself? 如何可以填充包本身的依赖?
Browserify Shim's tagline is: Browserify Shim的口号是:
Makes CommonJS incompatible files browserifyable.
使CommonJS不兼容的文件可浏览。
Your issue here is that react-lite
is already CommonJS compatible. 你的问题是
react-lite
已经与CommonJS兼容了。 For any CommonJS compatible file, Browserify will automatically add its dependencies
and peerDependencies
as appropriate, before Browserify Shim gets involved. 对于任何CommonJS兼容文件,Browserify将在涉及Browserify Shim之前自动添加其
dependencies
和peerDependencies
。
I suggest you change the peerDependencies
entry in the react-nouislider
package to the appropriate version of react-lite
and remove your Browserify Shim config above as it's no longer needed. 我建议您将
react-nouislider
软件包中的peerDependencies
条目更改为适当版本的react-lite
并删除上面的Browserify Shim配置,因为不再需要它。 When you do this, be sure to run any tests in the react-nouislider
package to make sure it still works with react-lite
instead of React. 执行此操作时,请确保在
react-nouislider
软件包中运行任何测试,以确保它仍可与react-lite
而不是React一起使用。 A good way of doing this is forking react-nouislider
to your own repo, making the change there, and pulling from that repo in your package.json
. 这样做的一个好方法是将
react-nouislider
分叉到您自己的存储库中,在其中进行更改,然后从package.json
该存储库中提取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.