我们有一个Angular项目,我们正在尝试使用AWS CodePipeline部署该项目。

我们已经将项目推送到CodeCommit存储库。

现在,我们面临着使用AWS CodeBuild生成构建的挑战。在CodeBuild中,构建定义为

phases:
  build:
    commands:
      - npm install && ng build-prod

我们收到错误ng: not found
我们还尝试了以下构建定义:
phases:
      build:
        commands:
          - npm install && run build-prod

我们得到的错误是run: not found
另外,我们不确定在“输出文件”字段中必须输入什么。

请帮忙..!!

最佳答案

CodeBuild的Node.js容器未安装angular-cli。只是Node.js和npm。在构建项目之前,必须先安装angular-cli。上面是一个将在S3存储桶中部署的角度项目的buildspec.yml示例:

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

10-08 06:35
查看更多