Being unable to find a really concise description at a stable endpoint, the "scripts"
-section of package.json
, central to node
/npm
/yarn
/euh. JavaScript-development these days, here it is.
The package.json
is a json file which typically contains things like version and name of a project, the typical metadata. It also contains the dependencies of a project. But this is about the scripts-section. Completely optional, but so convenient that typically your project has one already:
{
"name": "hello world",
"version": "0.0.1",
"main": "index.js",
"scripts": {
}
}
The "scripts"
-section contains snippets of code that you typically run using npm
or yarn
:
So let’s say you’re typing git add . && git commit -m "wip" && git push
a lot (totally not recommended), you could do:
{
"name": "hello world",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"wipitup": "git add . && git commit -m \"wip\" && git push"
}
}
and run it:
npm run wipitup
or
yarn run wipitup
Or, let’s stick with the actual goal of this project, the good ol’ hello world:
{
"name": "hello world",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"hello": "echo \"Hello World!\""
}
}
… and do either npm run hello
or yarn run hello
. That’s it, hard to call it concise otherwise :)
Enjoyed this? Follow me on Mastodon or add the RSS, euh ATOM feed to your feed reader.
Dit artikel van murblog van Maarten Brouwers (murb) is in licentie gegeven volgens een Creative Commons Naamsvermelding 3.0 Nederland licentie .