I have authored several npm modules, all of which are designed to enhance existing libraries such as three.js or react.
While the packages appear to be downloaded, I have not received any feedback confirming whether they have been implemented correctly.
Dependencies
What is the main objective behind defining dependencies at a high level?
three.js:
The process can be confusing as each "extension" assumes the existence of a THREE
object within a certain context.
Therefore, my three.js module only includes:
"devDependencies": {
"three": "^0.88.0"
}
And it is utilized in this manner:
require( 'three-instanced-mesh' )(THREE)
This approach both makes sense and raises questions.
The module cannot function without three.js and a proper context provided (via THREE
), but since it is passed in at runtime(?), it may not truly be considered a dependency. However, when working on the repository and wanting to develop within it, installing three.js
becomes necessary for the code to run.
React
I have released a React component with the intention that it should be used as follows:
npm install my-module
import MyModule from 'my-module'
<MyModule/>
However, for some reason, I listed react as a peerDependencies
dep.
Using <MyModule/>
in JSX presupposes that measures have been taken to ensure react is already accessible in this context (similar to passing in THREE
in the first example?).
The key difference lies in the fact that the class is not defined at runtime here, so importing it using import MyModule
necessitates having react available in MyModule.js
.
What exactly is the desired goal and how can it be articulated? All I know is that I do not wish for npm install my-module
to result in a different version of react being installed, or causing additional react to be bundled into the final build (although I am uncertain about this).
What type of dependency (if any) should react
be with respect to my-react-component
, and how can it be effectively linked to my module?
For instance, should one utilize the externals
feature with webpack or actually implement import React from 'react'
?
Build
If I configure my repo to function with cutting-edge JS (or perhaps even something other than JS), what exactly should I publish and how?
import Foo from 'foo' //<-- where does 'foo' point and what is 'foo'?