If you are writing a program that is intended to be used by others,
then the most important thing to specify in your package.json file is
the main module. This is the module that is the entry point to your
program.
和
If you have a lot of JavaScript code, then the custom is to put it in
the ./lib folder in your project.Specify a main module in your package.json file. This is the module
that your users will load when they do require(‘your-library’). This
module should ideally expose all of the functionality in your library.If you want your users to be able to load sub-modules from the “guts”
of your library, then they’ll need to specify the full path to them.
That is a lot of work to document! It’s better and more future-proof
to simply specify a main module, and then, if necessary, have ways to
dynamically load what they need.For example, you might have a flip library that is a collection of widget objects, defined by files in the flip/lib/widgets/*.js files. Rather than having your users do require(‘flip/lib/widgets/blerg.js’) to get the blerg widget, it’s better to have something like: require(‘flip’).loadWidget(‘blerg’).