Help me with my first mini library for BabylonJS

Hi! I trying to create my own npm package for BabylonJS.
Could give advice how to improve my package and which potential problems does it have now?
Firstly I worrie about dependencies description in the package.json, is it correct? Should I add @babylonjs/core into usual dependency or devDependency?

Here is the link: GitHub - Dok11/attach-node-to-scroll: Behavior class for BabylonJS that adds ability to attach scroll event to animation progress

Welcome to any critic or improvement suggestions!
I want to learn how to create npm packages and use best practices as much as possible.

1 Like

Oh wow! That’s awesome :slight_smile:

These is always a never-ending list of improvements. And no one gets it perfect ever :wink:

Just a few things from looking at the code a few minutes:

  1. You should tell npm which files to publish using the “files” key in package.json. Otherwise only the index.js file will be deployed.
  2. Babylon should be a dev dependency AND a peerr dependency. Now - the dev dependency can have a fixed version, but the peer dependency is the one defining what version of babylon will work with this plugin. The more generalized you make it, the more people will be able to use it. Are you using features that were introduced in 5.20.0? then this is the minimum version that you support. Maybe > 5.0.0 works? You should check that :slight_smile:
  3. You should build both cjs and mjs (commonjs and esm as module output).
  4. You should include the build scripts in package.json. I assume you use typescript?
  5. when importing from @babylonjs/core import from the right file and not from the main directory to improve tree-shaking (the first line in AttachNodeToScroll.ts
  6. Document your API, so people importing it will see the codedoc.
  7. IMO - you don’t need to commit the dist folder. The dist folder will be included when pushing it to npm, but github is not for dists. Some will argue that it is a good thing (there are advantages), this is more of a personal opinion.
  8. Fix your readme:

I guess there are a few other things, but that’s a start.

1 Like

Thank you for these advices!
I implemented them and push to git, could you check it again? I am not sure is I made these fixes correct :slight_smile:

And one question more, do I need to put;

into scene.onBeforeCameraRenderObservable.addOnce();?