I'm writing an automated build script that needs to run ng build
in a specific directory. My project has the following structure:
project
├ build-script
└ project-client
└ package.json
ng build
is looking for the package.json file, but it can't find it in its current location. Is there a way I can direct ng build
to the subdirectory without doing a cd
(since bash is a bit wonky about changing directories)? Essentially, I just need a way to tell ng build
to operate in a directory that I specify.
I have tried doing ng build ./project-client/
but it is giving the error that "You have to be inside an angular-cli project in order to use the build command"
Thanks.
ng serve. To get the application running, the ng serve command must execute within the [name-of-app] folder. Anywhere within the folder will do. The Angular CLI must recognize that it is within an environment generated with ng new .
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.
ng build
)Since Angular already has a shortcut for this command, you can simply run
npm run build --prefix path\to\Angular\project
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With