I have a Lerna monorepo that consists of two packages: myapp-web
and myapp-core
. Each of those packages have top-level src/
dirs to hold their code.
I want to be able to import myapp-core/src/some-subdir
as myapp-core/some-subdir
(similar to how you'd do an import to lodash/effects
or lodash/fp
) inside of myapp-web
(that is, I want to avoid including the src/
part).
I know you can set the entry point in the main
prop of package.json
. Can I do something analogous but manifesting the directories I want to make available from outside the package? Do I need to make named exports from the main
file and require picks those up as myapp-core/some-export
?
The only way to do this is to move the files from src/
to the root of you project. However you can set this up to happen on publish. That way you keep your source files in src/
and exclude them from your published package. That's what lodash
and others do.
This is not unique to monorepos.