问题
I'm looking to create an app with optional modules that I will not know the names of in the application.
For example, imagine outlook, but the calendar/tasklist/mail pieces are optional components, you would npm install outlook-framework then create your app that requires "outlook-framework" but then I would like to import all packages installed that start with "outlook-". So I can npm install outlook-mail and that gives me email support, same for outlook-calendar, or even something I didn't write, maybe outlook-twitter or outlook-rss (or thirdpary-outlook-module)
Is there some existing mechanism for loading modules like this? Or does anyone have any better ideas for loading unknown, optional modules?
Thanks!
回答1:
I've decided that the packages will need to have a manifest, like "outlook-manifest.json" and to load the modules, I'll list directories in node_modules, find directories with a manifest, and load those.
来源:https://stackoverflow.com/questions/34533173/best-way-to-implement-optional-modules-for-node-js-app