AWS codebuild在构建期间从Node软件包中删除dev依赖项

问题描述 投票:0回答:1

我在NodeJS中有一个应用程序,该应用程序是使用AWS CodeBuild构建的,然后使用SAM部署到AWS lambda。我想在构建阶段之后从项目中删除所有devDependencies。在构建阶段,我运行所有需要devDependencies的测试,但我不希望将它们作为工件移植到S3时与其他模块一起压缩。

我的buildspec.yml

 version: 0.2

phases:
    install:
        commands:
        # Update libs
            - echo Executing the install phase.
        runtime-versions:
            nodejs: 10
    pre_build:
        commands:
        - npm install
    build:
        commands:
        - echo Executing the build phase.
        - npm run test
        - export BUCKET=alexa-v1
        - aws cloudformation package --template-file template.yml --s3-bucket $BUCKET --output-template-file outputtemplate.yml
    post_build:
        commands:
        - echo Build complete

artifacts:
    type: zip
    files:
      - template.yml
      - outputtemplate.yml

我不确定在post_build中添加npm prune --production是否是正确的方法。

node.js amazon-web-services aws-lambda aws-codebuild
1个回答
0
投票

尝试使用AWS SAM CLI代替常规的AWS CLI。特别是,打包应用程序时,例如可以使用sam package命令。

sam package \
  --template-file template.yml \
  --s3-bucket $BUCKET \
  --output-template-file outputtemplate.yml
© www.soinside.com 2019 - 2024. All rights reserved.