typescript export sub-modules without "dist" folder

Viewed 1131

I have a simple module modA:

modA/
- package.json
- dist/
  - index.js
  - db.js
  - stuff.js

I'd like to be able to use the submodules "db" and "stuff" like this: import * as db from modA/db -- how can I do that? I have main: dist/index.js in my package.json but that doesn't set dist/ as a default for submodules, so the only way I can get it to work is import * as db from modA/dist/db (explictly including the "dist" in the import). import * as db from modA/db just gives the "Cannot find module" error.

The dist is there because I'm compiling from typescript.

In case it's important, I want this to work in node.js and browser, where I'm using webpack.

As an alternative, can I add some kind of namespace re-export code in index.js to make this work?

1 Answers
Related