Fellow Stranger
Fellow Stranger

Reputation: 34013

Calling one script from another with Yarn

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

Answers (2)

Murage
Murage

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

L. Faros
L. Faros

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 prebuildshould work. Also you could just do yarn run clean.

Documentation of the run cli : https://yarnpkg.com/lang/en/docs/cli/run/

Upvotes: 9

Related Questions