The scripts property in package.json are command lines that:
They are also known as npm scripts because npm is historically the first package manager.
{
"scripts": {
"world": "echo hello world",
}
}
yarn world
# or
npm world
yarn run v1.22.19
$ echo hello world
hello world
Done in 0.13s.
To run a script, you would execute the following npm command
yarn scriptName
# or
npm run scriptName
To run the script sequentially on all platform. https://www.npmjs.com/package/npm-run-all
Example with the release script:
"scripts": {
"build": "cross-env NODE_ENV=production webpack --mode 'production'",
"test": "jest",
"publish": "npm publish",
"release": "npm-run-all test build publish",
}
From the VsCode IDE in a VsCode - Task (tasks.json)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "test",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The execution depends on your package manager. You should check the documentation for the run command. For example for yarn.
Otherwise, generally, the search path is modified for the duration of the run.
Within scripts, you can reference locally installed npm packages by name instead of writing out the entire path. This convention is the standard in most npm-based projects and allows for instance to directly call a package. Example: