简体   繁体   中英

Publish two versions of npm module with different dependencies

I'm working on a node library which is distributed in two versions: full and lite. The lite version uses a shorter list of dependencies than the full one and I build them using two webpack configurations with different entry points. The problem is that in package.json there is only one "dependencies" list so even if in fact the lite version won't need many dependencies when consumers will install the library they will still fetch all of them. What can be the approach to solve this?

I think you have to create two separate packages. If possible, make the "lite" version a dependency of the "full" version, to limit the amount of overlap.

You could then name and publish both versions as scoped packages :

"name" : "@your-package/full"

And:

"name" : "@your-package/lite"

Another approach would be to do what for instance Sequelize does with its database drivers: don't depend on any, and when the user tries to use a particular driver, emit a message that they need to install that particular driver package first. In your case, if the user tries to use some "full" functionality, but you detect that they're using the "lite" version, show instructions on how to install the full version.

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