For reusable components:
- Put a
react
dependency in both peerDependencies
and devDependencies
.
- Never put a
react
dependency in dependencies
.
peerDependencies
specifies which version(s) of React your reusable component supports/requires. When using npm 2 this also adds React to the list of modules to be installed, but this is no longer the case with npm 3.
devDependencies
ensures React will be installed when you run npm install
while developing your component, or when running tests on Travis or similar.
Putting react
in dependencies
will cause multiple versions of React to be installed if somebody uses your component but has a different version of React in their own package.json
- having multiple versions of React not only bloats the build, but also causes errors when different versions try to interact.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…