Reputation: 3570
I have a TypeScript project that I am publishing as an NPM module. The output of compiling the project is in the directory {mymodule}/dist/src/...
which means that when I publish, the NPM module also takes the above file structure.
The drawback to this is when individual modules needs to be required, it would look like this:
var individualModule = require('/dist/src');
I would like to flatten the output of the published module, where the files in the published module will be {mymodule}/...
instead of {mymodule}/dist/src/...
Upvotes: 2
Views: 828
Reputation: 8467
In my opinion the correct way of doing this is to intentionally expose modules from your package via module.exports
(or import/export
) in the root file.
const exposableOne = require('/dist/src/ex-1.js');
const exposableTwo = require('/dist/src/ex-2.js');
// ...
module.exports = { mymodule, exposableOne, exposableTwo };
You can take a look at the main Express framework file - they doing almost the same thing using exports.
directive.
Not exactly TypeScript stuff but idea is quite common.
UPDATE:
If you really need to do this without binding via require/exports
, than you could use the symlinks approach. I'm not sure that this option works well on all platforms, but for an example you can check this solved issue and this repository on GitHub. aliases
directory in the latter contains files that are symlinked to the recipes
directory modules.
Upvotes: 1