Search code examples
javascriptecmascript-6

External exports vs Internal exports from a project


I am developing a browser Javascript project/library that consists of multiple packages/modules. I am using lerna to manage the project and rollup to build each package. There is one main package that contains the core functionality and several other packages that use the core functionality. So the core package needs to export all the functionality required by the additional packages. The user of the project/library, (in order to build an application) does not need to know about all that exported functionality but only a small portion of it.

So how do I go about splitting the huge export list of the core package to an external facing one and an internal facing one? Can this be done? What tools do I need to use?


Solution

  • It mostly sounds like your modules aren't laid out properly.

    Usually, one architects modules with two things in mind, what you want to share and use internally within the project and what you want to share externally. In some cases, you "repackage" a subset of the internal exports as external imports in their own exported file and use that as the clearinghouse for what is publicly exported.

    That external exports file can then import from elsewhere and then re-export just what is for public consumption. Without seeing actual code with actual modules and actual imports/exports, it's hard to be more specific than that.