1.0.5 • Published 5 years ago
@wns-test/wns-test-ms v1.0.5
Publish a npm package
Initialization and manual publish
Initialize and first publish
- initialize a new npm project
npm init -y- change the name in package.json to
@organization/project - initialize git repository and commit
- publish your package
npm login
npm publish- check your profile on https://www.npmjs.com/
Write a typecript package
- create
tsconfig.json
tsc --init- install dependencies
npm install typescript del-cli --save-dev- create
src/index.tswith some ts code - update
tsconfig.json
{
...
"declaration": true, /* Generates corresponding '.d.ts' file. */
"outDir": "./build", /* Redirect output structure to the directory. */
...
}- update
package.jsonscripts to be sure to clean thebuilddirectory
{
...
"scripts": {
"clean": "del .build/*",
"build": "npm run clean && tsc"
},
...
}make sure to gitignore
build/fill
main,typesandfilesinpackage.json
{
...
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"./build/**/*"
],
...
}Update and publish new package version (manually)
- commit your changes
- update your version number manually or run command:
npm version patch- build and publish
npm run build
npm publishPublish automatically with a Github action
Connect to a remote github repo (if not done yet)
git remote add origin git@github.com:**github-account**/**project-name**.git
git branch -M main
git push -u origin mainnpm publish token
- create and copy a
npmpublish access token - create a repository secret NPM_TOKEN on your Github repository
Create a publish action
- copy
.github/workflows/publish.ymlin you repository - before pushing to
mainthink of update the package version