2.2 KiB
Packages
All packages should be under this folder
Create package
-
Create a folder to represent your NPM package under this packages folder. Name your folder same name as your package.
-
Create a .npmrc file in the project folder with the content
registry=<your registry>
always-auth=true
- Connect to the feed
npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false
vsts-npm-auth -config .npmrc
-
Run
npm init
under the project folder and answer a few questions. You could edit them in the generatedpackage.json
after that. -
Run
npm publish
to publish the package to the feed.
NOTE
The easiest way to create a new NPM package is just to copy an existing one and make sure you rename the folder
and most importantly rename the name
field in the package.json
file at the root of your package's folder.
Also important is that the location of where your package will be uploaded to is determined by the lines shown in step 2 of .npmrc file that is at the root of your package folder.
Installing and using your package from another NPM package or website
-
Update the
package.json
file of the project that would like to consume your package. -
Add
"your_package_name": "1.0.0"
(or whatever version you want) under the"devDependencies"
field. -
Run
npm install
to install your package to the consuming project. The package will be dropped under thenode_modules
folder under your root folder. -
Now build your consumer website or package like before via
npm run build
ornpm run dev
.
NOTE
If step 3 fails, it is because you did not add your assigned npm credentials to the .npmrc file. While it may be tempting to add this
auth token in the .npmrc file
located at the root of your package folder. DO NOT DO IT!
as the .npmrc file at your root
folder should be checked in with your sources. The auth token should be added to the .npmrc file located under C:\users\<alias>\.npmrc
.
This auth token will generally expire every 3 months.
NOTE
If you ever lose your auth token, you can always repeat steps 1 thur 4 to get a new one.