FHell / COVID-Game

A simple explorable/visualization/game of the effect of covid countermeasures
https://fhell.github.io/COVID-Game/
BSD 2-Clause "Simplified" License
2 stars 0 forks source link

Project structure and use of npm #7

Open elondaits opened 3 years ago

elondaits commented 3 years ago

I see something that I found a bit weird, but could be intentional: a node_modules directory in the repository with no package.json file.

Normally (and again, maybe this is intentional... in which case sorry for stating something which may be obvious) the way JS projects go is:

... so whenever someone wants to use the project, they clone and then run npm install so all dependencies are automatically downloaded. node_modules is normally not placed in the repository, because it gets very big and it's all 3rd party code... plus, it might contain platform-specific code, since some modules use native code.

Now, use of npm modules (the ones that go in node_modules) creates some challenges for web applications... since this originally was a way to import modules into node.js, and not something designed for the web. The standard way to deal with these issues is to bundle code specifically for the web through a tool such as Webpack or Browserify. What these tools do (hope I'm not webplaining too much) is to go through the js code dependency tree (your code + modules) and create a single flat js file that has everything in it, with all module references "resolved"... said file can be included in the html. Sometimes this step also includes transpiling, to target the code for older browsers.

I simplified things a bit, but that's the basic thing. The main downside of this is that you have to add a compilation step, which can be made automatic but still can slow down the development process a bit. Another downside is that depending in which tool you use you might have to take some extra steps so your code gets published on github pages (basically because some tools, like webpack for instance, require that "compiled" code go into a separate directory and not the root of your project).

So, I understand that right now you're running some of the code through node.js ... but it's possible that you'll have to deal with these issues when moving it to the front end... and also, if you're incorporating more npm modules you'll want to use npm and package.json to avoid commiting platform-specific code, etc.

FHell commented 3 years ago

Thanks for the info! I did not know any of this, I never used node/npm before (everything before this was all self rolled) but needed a package that implements the negative binomial distribution. I can possibly get rid of this dependency if that simplifies development sufficiently (I thought it was doing something more clever than it seems to be doing which I might be able to replicate.)

elondaits commented 3 years ago

No need to remove the dependency for now. If necessary I can help with bundling it before shipping, since I do it all the time.