https://www.npmjs.com/package/@vercel/ncc
is pritty capable of solving your cjs versions generation on a project base you will never want to publish the CJS dependencies you should adopt the following pattern.
you create so called dev bundels of your dependencies so your dependencies get a own package.json and bundler config then you run that only when you add or remove external dependencies to your project.
then you use the resulting bundle in your main project. and also commit that to the main project as it is a required dependencie
this is called a dev-bundle.
Short version
You should avoid publishing your own CJS dependencies as packages. you should bundle them and commit that bundle to your main project and create a indipendent package or project to build only your external dependencies as CJS modules.
https://www.npmjs.com/package/@vercel/ncc
is pritty capable of solving your cjs versions generation on a project base you will never want to publish the CJS dependencies you should adopt the following pattern.
you create so called dev bundels of your dependencies so your dependencies get a own package.json and bundler config then you run that only when you add or remove external dependencies to your project.
then you use the resulting bundle in your main project. and also commit that to the main project as it is a required dependencie
this is called a dev-bundle.
Short version
You should avoid publishing your own CJS dependencies as packages. you should bundle them and commit that bundle to your main project and create a indipendent package or project to build only your external dependencies as CJS modules.