We have an Angular project and we are trying to use AWS CodePipeline to deploy the project.
We have pushed our project to a CodeCommit repository.
Now we are facing challenge to generate the build using AWS CodeBuild. In CodeBuild the build definition is
phases:
build:
commands:
- npm install && ng build-prod
We get an error ng: not found
We also tried the following build definition:
phases:
build:
commands:
- npm install && run build-prod
Error we get is run: not found
Also we are not sure about what we have to enter in "Output files" field.
Please Help..!!
The Node.js container from CodeBuild doesn't have the angular-cli installed. Just Node.js and npm. You must install angular-cli before build your project. Above there are a buildspec.yml example for a angular project to be deployed in S3 bucket:
version: 0.2
env:
variables:
CACHE_CONTROL: "86400"
S3_BUCKET: {-INSERT BUCKET NAME FOR STATIC WEBSITE HERE-}
BUILD_FOLDER: {-INSERT THE NAME OF THE BUILD FOLDER HERE-}
BUILD_ENV: "prod"
phases:
install:
commands:
- echo Installing source NPM dependencies...
- npm install
- npm install -g @angular/cli
build:
commands:
- echo Build started on `date`
- ng build --${BUILD_ENV}
post_build:
commands:
- aws s3 cp ${BUILD_FOLDER} s3://${S3_BUCKET} --recursive --acl public-read --cache-control "max-age=${CACHE_CONTROL}"
- echo Build completed on `date`
artifacts:
files:
- '**/*'
base-directory: 'dist*'
discard-paths: yes