Running `ng build` in a specific directory
When I need to go to certain directory just to run a script I usually use pushd
and popd
. Example:
pushd /path/to/dir
ng build
popd
After this snippet is run your working directory (pwd
) will remain unchanged.
Note: This answer is specific to Angular commands
You can leverage the npm run
command to run an Angular command while using the parameter --prefix
to indicate the sub-directory.
Example 1: Original question (ng build
)
Since Angular already has a shortcut for this command, you can simply run
npm run build --prefix path\to\Angular\project
Example 2: Custom command (Eg: ng build --prod
)
First, create a shortcut for this command in your package.json
file
{
"scripts": {
// "CMD-SHORTCUT": "custom-command"
"prod-build": "ng build --prod"
},
}
Then, run the new shortcut in the same way as example 1:
npm run prod-build --prefix path\to\Angular\project