Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Configure The ‘script’ tag In package.json To Run Multiple Commands

You are prob­a­bly used to using the scripts defined in your scripts tag to start your nodejs server if you’re using node­mon. Turns out that the script tag can be a tad more use­ful than just that. For exam­ple, you can run mul­ti­ple com­mands in a from a sin­gle script. e.g.

Lets say we have a cou­ple of grunt tasks

  • jsBuild: Con­cate­nates and mini­fies our js files.
  • css­Build: Con­cate­nates and mini­fies our css files.
  • watch: Keeps an eye when any changes are made to our .js files and .css files and trig­gers a jsBuild and cssBuild.

To run tasks in par­al­lel, sim­ply seper­ate them with an &

To run tasks sequen­tially sim­ply seper­ate them with an &&

scripts: {
   buildAll: 'grunt jsBuild & grunt cssBuild'
}

Now you have the fol­low­ing com­mands at your dis­posal in the shell from your project’s root Directory

npm run buildAll
npm run dev

Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.