I am looking to develop an NPM package that organizes imports into modules for better organization.
Currently, when I integrate my NPM package into other projects, the import statement looks like this:
import { myFunction1, myFunction2 } from 'my-package';
However, I would prefer to have the imports separated into modules like so:
import { myFunction1 } from 'my-package/products';
import { myFunction2 } from 'my-package/sales';
package.json
{
"name": "my-package",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf ./dist && tsc"
},
"devDependencies": {
"typescript": "^5.2.2"
}
}
tsconfig.json
{
"compilerOptions": {
"incremental": true,
"target": "es2020",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"baseUrl": "./src",
"declaration": true,
"outDir": "./dist",
"removeComments": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"strictNullChecks": false,
"skipLibCheck": true
}
}
src/index.ts
export { myFunction1 } from './products';
export { myFunction2 } from './sales';
Your assistance is much appreciated. Thank you!