The REST API CMS app we built in the Coldbox Hero to Superhero class was extremely helpful in getting my feet wet understanding how an HMVC app should be laid out. The class inspired me to start thinking about everything as a separate module and how I could break things out into independent reusable components. The concept is pretty straightforward when it comes to server-side code, but I’m having difficulty wrapping my head around how to best go about creating a sub-module in a Coldbox app with its own front-end dependencies that are installed through something like NPM.
Let’s say you’ve created a shiny new submodule that you want to use as the
/admin/ folder in a website. The admin area is going to have its own front-end dependencies separate from the root level pages (e.g. Bootstrap, Fontawesome, jQuery, etc…). Normally I would use NPM to keep track of dependencies and store them in a tracked
/admin/package.json file. However, when I want to deploy my app, I would need to manually navigate to the
/admin/ submodule and type
npm install to install everything. This feels like a code smell to me - imagine if you had a bunch of sub-modules, each with its own NPM dependencies! Surely there must be a better way?
Another idea would be to group all of the NPM dependencies into a root-level
/package.json file so that I only have to type
npm install once at the root level and it would install all sub-module dependencies. However, this also feels like a code smell because it means the root application will need to know every sub-module’s NPM dependencies.
Perhaps there is a magic Commandbox module that will handle nested
package.json files? I didn’t see anything in Forgebox. I know Elixir has support for submodules, but based on the docs I can’t tell if this is the right path to go down because it feels more suited towards bundling things together with Webpack. I also couldn’t find any examples of apps that use Elixir to accomplish something like this.
Is there a best-practices way to proceed with developing apps with submodules with their own NPM dependencies?