aka Node Packaged Modules o npm.
És el gestor de paquets oficial de Node.js i està disponible automàticament amb l'entorn Node.js.
https://laracasts.com/series/how-do-i/episodes/2
$ sudo apt-get install npm
Necessita que hi hagui a la carpeta on s'executa un fitxer:
package.json
El primer de tot és tenir configurat node.js/npm amb:
$ npm set init.author.name "Brent Ertz" $ npm set init.author.email "[email protected]" $ npm set init.author.url "http://brentertz.com"
En el meu cas:
$ npm get init.author.name Sergi Tur Badenas $ npm get init.author.email [email protected] $ npm get init.author.url http://acacha.org
I ara executeu:
$ npm adduser
Per crear un usuari al aweb de npm i obtenir un token per a fer les operacions. Les dades es guarden al fitxer ~/.npmrc:
$ cat ~/.npmrc init.author.name=Sergi Tur Badenas [email protected] init.author.url=http://acacha.org //registry.npmjs.org/:_authToken=TOKEN_HERE
Ara ja podeu anar al projecte que voleu publicar i executar
$ cd projecte $ npm publish
IMPORTANT: Vegeu Javascript Modules per que el vostre projecte ha de seguir el format d'un mòdul vàlid
Resources:
npm link
$ cd <viking-project-root> $ npm link # this should install a global symlink to the local project $ cd <tudor-project-root> $ npm link viking # will create a symlink locally to the global viking # symlink $ # voila! now we can develop the two projects side-by-side without # having to worry about publishing either of them
On tudor és un projecte que depèn del projecte viking que és el projecte que estem desenvolupant
npm pack
Resources:
Comanda
$ npm version
Format:
$ npm version --help npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
Normalment voldreu publicar una versió menor (vegeu Semver)
$ npm version patch $ npm publish
Recordeu també els tags de git:
$ git tag -a version_here $ git push origin version_here
https://github.com/acacha/forms
Creació de transpiled ES6 modules/ES6 modules utilitzant transpilers com Babel. Bàsicament el truc està en escriure el codi amb ES6 i utilitzar Babel per passar el codi a ES5. Tindrem dos carpetes:
Per tant les configuracions de .npmignore i .gitignore són:
Fitxer .gitignore:
node_modules dist
Fitxer .npmignore
src
I al fitxer package.json tindrem scripts npm per realitzar les tasques de transpilació:
"scripts": { ... "build": "babel src --presets babel-preset-es2015 --out-dir dist" "prepublish": "npm run build" },
recordeu d'instal·lar babel:
$ npm install --save-dev babel-cli babel-preset-es2015
I també compte de modificar l'opció main:
"main": "dist/index.js",
Resources: