What you'll learn
- how to use the
workspaces runcommand in order to execute a single command on multiple packages in your Webiny project
Every Webiny project is organized as a monorepo and as such, it consists of multiple packages, or in the context of monorepos, multiple workspaces.
Depending on the project size, a single monorepo can contain anywhere from a couple to dozens of packages. When the latter point is reached, executing different commands on packages, one by one, simply becomes ineffective. That's why, the Webiny CLI introduces the
workspaces set of commands.
Workspaces vs. Packages
workspaces run command#
Webiny CLI provides the
workspaces run (or
ws run for short) command that enables you to run a single command across multiple workspaces at once. The common use case where this might be needed is local development, where you want to watch for code changes on multiple packages, and rebuild them accordingly.
For example, in order to establish a watch session across multiple packages, located in a specific folder, you can run the following command:
On the other hand, if you wanted to build all of the packages, again, located in a specific folder, you can run:
When deploying your project applications, building of packages is done automatically for you, as explained in the Deploy Your Project tutorial.
Note that the
workspaces run command runs the commands specified in the
webiny.config.js file, and not the scripts that might've been defined in packages'
package.json file, in its
webiny.config.js is almost always present in every package. For example, your React applications might have something like the following:
All of the commands are listed in the
commands property of the exported object.
In the above shown examples, we've used the
--folder argument, to instruct the
workspaces run to run the command only for packages located in the
./awesome/packages folder. Instead of the
--folder argument, you can also use the
--scope argument, which enables you to filter the packages by their name. For example:
If a Webiny command you're trying to run expects additional arguments, you can pass them as usual. For example, for certain packages, the build command might expect the environment to be specified, via the
--env argument. So, simply append it to the
workspaces run command, like so:
Once executed, the
workspaces run command first retrieves a list of all packages, specified via either the
--scope argument. After that, the command requires the
If you're running a specific command for multiple packages, and some of the packages don't have it defined in its
webiny.config.js, those packages will simply be ignored. Ultimately, for each package, the command gets executed only if it's actually defined in the
Can I add more commands in the
Yes, you can. Feel free to expand it in any way needed.