Running NPM scripts sequentially
You can prefix your scripts pre
and post
so they will execute automatically:
"scripts": {
"prebuild": "echo \"Welcome\" && exit 1",
"build": "start cmd.exe @cmd /k \"yo esri-appbuilder-js:widget && exit 1\"",
"postbuild": "start C:\\WebAppBuilderForArcGIS\\startupShortcut",
"exit" : "start cmd.exe @cmd /k \"echo \"goodbye\" && exit 1\""
}
then run npm run build
Invoke these scripts via npm run and chain them with double ampersand &&
:
npm run pre-build && npm run build_logic && npm run post_build && npm run exit
Explanation:
- Use
&&
(double ampersand) for sequential execution. - Use
&
(single ampersand) for parallel execution.
Following @Mobiletainment's great answer, you can also use npm-run-all to make the command much shorter and much more readable. In your case:
"scripts": {
...
"build": "run-s pre-build build_logic post_build exit"
}
run-s
is a shortcut npm-run-all
provides, that runs all the given npm-scripts sequentially, hence the -s
(run-s
is a shorter version of npm-run-all -s
).