2023-11-09|閱讀時間 ‧ 約 2 分鐘

npm use local package

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.

分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.