All my library functionality and types are exported from the main index.ts file.
-- Exporting directly from the index.ts file is not possible. The TypeScript project needs to be compiled into JavaScript for consumers to use. This results in the creation of a 'dist' folder where the compiled JavaScript files should be placed along with the package.json file. Declaration files can be generated using Typescript and stored in the dist folder.
The challenge now is how to conceal the 'dist' folder from direct importing by consumers.
Three options are available - Traditional Bundler, Barrel pattern, or package exports.
Bundler approach: Bundle all files into one using tools like Webpack or Rollup, resulting in a single output file that would be specified as the 'main' field in the package.json.
Barrel exports: Utilize the Barrel Pattern to compile the package with plain Typescript, placing the files in a dist folder while setting the barrel export file as the 'main' configuration.
Package.json exports: Opt for Node.js package exports for a future-proof method of concealing internal modules in the 'dist'. However, this may not be compatible with older versions of Node.js and has limited tooling support.
A recommended approach would be to combine Barrel exports with package.json exports.
Rullup is ideal for bundling libraries, while Webpack is preferred for bundling applications.