Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

yarn
yarn scripts

What are Yarn scripts?

Aymen Bashir

Scripts are used to automate package-related tasks, such as building processes. The scripts field is defined in the package.json file in the following way:

{
  "scripts": {
    "[script]": "[script definition]"
  }
}

The defined script can be run using the following command:

yarn run [script]

If the yarn run command is executed without a script name, then the names of all the scripts available for a package are listed. Moreover, additional arguments can also be passed with the yarn run command, as shown below:

yarn run [script] -o --watch

We can also specify a script to run before or after one another by using the prefixes pre and post, as shown below:

{
  "scripts": {
    "make": "[script definition]",
    "premake": "[script definition]"
  }
}

Running yarn run make will first execute premake and then make script. A locally installed executable can also be executed as a script. Such a script is located inside node_modules/.bin/. For such scripts, the run command can be left out.

yarn [script]

RELATED TAGS

yarn
yarn scripts

CONTRIBUTOR

Aymen Bashir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring