By the sounds of it, what you're wanting to do is package up your local my-module
so that it can be used in the same way you'd install and use a package from the npm registry.
When you're doing local development, its easy to configure a dependency to reference to your module as a file path - though you need to have your typescript transpiled for it to work in your case.
Here's the method I'm using for local development, in an environment where we have many utility modules for a microservices architecture. I package the module into an archive and install it using npm install
:
- Use
npm pack
to package the module into a .tgz
. Our package.json
defines the target directory to be packaged, and the build
script performs the transpile into the target (obviously adjust for your needs):
...
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "npx babel src --out-dir dist --extensions .ts,.tsx,.js --ignore **/*.test.ts,**/*.test.tsx",
...
- Run
npm pack
and install the generated package in your application
/my-module/> npm pack
/my-module/> cd ../my-app
/my-app/> npm install --save ../my-module/my-module-0.0.1.tgz
Or as an all-in-one (builds tgz
in my-app
dir):
/my-app/> && npm pack ../my-module && npm i -s my-module-0.0.1.tgz
Once you're done with development, you'll probably want to publish your module in a way that its available to your project(s) on deployment.
Your options are along the lines of:
- Publish to your local system using
npm link
- Publish to a private registry
- Publish to the npm registry (as either a public or private module)
Here's a good resource for these options: https://medium.com/@debshish.pal/publish-a-npm-package-locally-for-testing-9a00015eb9fd