This is difficult with
package.el is not designed for modular package management. I suggest you use a different package manager, such as
straight.el (which I wrote in order to solve the problems of
straight.el, conditionally loading a package is trivial: just conditionally load it:
This works because (unlike
straight.el does exactly what you ask it to, and nothing more. Thus, preventing
straight.el from installing and loading a package is as simple as not asking it to do so.
You can read verbose documentation about
straight.el, including comparisons to other package managers, in the README.
Footnote for advanced
If you use version lockfiles, then you want to be sure that the revisions of all your packages are recorded in your lockfile, even if they are not currently being loaded. This can be accomplished via
although a more convenient syntax using
use-package is planned in this issue.