简体   繁体   中英

NPM package.json main attribute and no suitable entry

I am trying to get my head around the best way to setup my package.json file. I have a JavaScript module full of reusable JS files. Let's call it Module1.

Module1 package.json will have its name attribute set to "Module1" so any modules depending on it can simply do require("Module1");. So far so good. However it also requires a "main" attribute pointing to the main JS file that will have its module.export returned from require. This is what I don't understand. Module1 doesn't have a main JS file, it is a collection of reusable JS files that each have its own module.exports returning the internal object in that file. There is no one singular JS file binding them all together that could be seen as a valid entry for main. Surely I can't just concatenate all these files together into a main bundle file? If so how would require know what to return if there are multiple module.exports?

Thanks for any help

Don't concatenate, you'll export from your entry point your other modules, like:

module.exports = {
  foo: require('./lib/foo'),
  bar: require('./lib/bar')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM