npm use local package

2023/11/09閱讀時間約 1 分鐘

When you want to use your non-publish yet package in your other project, you need to do these:

step 1 go to package and run :

npm link packageNameHere

// example: npm link @aliciaForDemo/stripe-api-helper/

This will link this package to global node_module.

step 2 go to directory which you want to use this package and run these

npm link pathToPackageDirectory

npm install pathToPackageDirectory

ex: npm link ~/myDemoPackage

This will link global node_moudle to this project.

Resolve module:

If you want to import package to file, USE FILE PATH INSTEAD OF PACKAGE NAME !

Ex: My package name is stripe-api-helper. my code are in src/index.ts then I need to resolve like this:

import { postStripe, Item } from '@aliciaForDemo/stripe-api-helper/src'

If u use ‘@aliciaForDemo/stripe-api-helper’ it will fail.

4會員
10內容數
分享感情與生活的故事,期望我們都能在愛與被愛的路上感到幸福,並且在這個只有活一次的人生裡好好的活成自己喜歡的樣子
留言0
查看全部
發表第一個留言支持創作者!