I've developed a basic module called modA
:
modA/
- package.json
- dist/
- index.js
- db.js
- stuff.js
My goal is to use the submodules "db" and "stuff" like this: import * as db from modA/db
-- how can I achieve this? My package.json
has main: dist/index.js
but that doesn't automatically apply to submodules, so I'm currently importing import * as db from modA/dist/db
(explicitly including "dist" in the import). Trying import * as db from modA/db
results in a "Cannot find module" error.
The inclusion of dist
is due to my typescript compilation process.
For context, I need this functionality to work in both node.js and the browser, using webpack.
On another note, is it possible to implement some sort of namespace re-export code in index.js
to make this setup functional?