This is a repo based on a break about npm.
- initialize the npm project
npm init (inside of a folder)
package.json
{
"name": "number-helpers-wolox",
"version": "1.0.0",
"description": "Get information about an array of numbers",
"main": "build/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"numbers",
"array",
"helpers",
"wolox"
],
"author": "Andres Alcaraz",
"license": "ISC"
}
UPDATE MAIN PATH
- Add libraries and typescript configuration
npm i babel-cli babel-preset-latest @babel/preset-env @types/babel__preset-env jest @types/jest watch @babel/preset-typescript --save-dev
tsc --init
config tsconfig.json:
"rootDir": "./src",
"moduleResolution": "node",
"outDir": "./build",
Create file .babelrc
{
"presets": [
"@babel/preset-typescript",
["@babel/preset-env"]
]
}
- Add base file
In src/index.ts
console.log('Hello Wolox');
node src/index.ts
- Add base scripts
"test": "jest",
"build": "tsc -p tsconfig.json",
"dev": "watch 'npm run build' src",
"test:watch": "npm test -- --watch"
- Add functionality
- Test locally
a. Create new empty project b. From the package run > npm link c. From the new project run: > npm link name-of-package d. test functionality
- Publish package
Add .npmignore
src
npm adduser npm publish
That's it, now you could install your package in any other project you want.