Reputation: 34013
Below is an example how to run a script from another with npm
in package.json
.
What's the equivalent with yarn
?
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"clean": "rimraf ./dist && mkdir dist",
"prebuild": "npm run clean",
}
}
Upvotes: 14
Views: 11249
Reputation: 656
Improving on @l-faros answer, Yarn also supports a shorter syntax
{
"scripts": {
"clean": "rimraf ./dist && mkdir dist",
"prebuild": "yarn clean",
}
}
and yarn prebuild
to run the script command.
The syntax allows one to omit the run
argument.
Documentation: https://classic.yarnpkg.com/en/docs/cli/#toc-user-defined-scripts
Upvotes: 8
Reputation: 1992
You could do
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"clean": "rimraf ./dist && mkdir dist",
"prebuild": "yarn run clean",
}
}
And then the command yarn run prebuild
should work.
Also you could just do yarn run clean
.
Documentation of the run
cli : https://yarnpkg.com/lang/en/docs/cli/run/
Upvotes: 9