如何使用Gulp Process.env.node_env获得AWS放大以在生产模式下构建?

发布于 2025-02-01 19:16:28 字数 1268 浏览 2 评论 0原文

我正在使用以下配置使用AWS放大:

  1. https://dev.example.com/ - aws amplify -branch = dev
  2. https://example.com/ - aws amplify -branch = master = master

in gulpfile中。 js我有规则适用于生产(使用)

const isprod = process.env.node_env ====='prod'prod'

这是我的amplify.yaml

version: 1
frontend:
  phases:
    # IMPORTANT - Please verify your build commands
    build: 
      # commands: []
      commands:
        npm run build:$BUILD_ENV
  artifacts:
    # IMPORTANT - Please verify your build output directory
    baseDirectory: /docs
    files:
      - '**/*'
  cache:
    paths: []

我尝试仅将产品应用于主人。我只希望使用产品模式并为主人运行。当我运行构建时,开发分支显示未启动的HTML,生产也是如此。它正在工作和构建,但是产品模式没有反映在生产中,因此它不会执行我的build prod命令。

我在线搜索并应用了环境变量,并遵循了此文档,该文档显示了构建过程“ https://docs.aws.amazon.com/amplify/latest/userguide/userguide/build-settings.html”如下:

仍然不起作用。

I am using AWS Amplify with the following configuration:

  1. https://dev.example.com/ - AWS Amplify - branch = dev
  2. https://example.com/ - AWS Amplify - branch = master

In gulpfile.js I have rules applied for production (minification etc using)

const isProd = process.env.NODE_ENV === 'prod'

This is my amplify.yaml

version: 1
frontend:
  phases:
    # IMPORTANT - Please verify your build commands
    build: 
      # commands: []
      commands:
        npm run build:$BUILD_ENV
  artifacts:
    # IMPORTANT - Please verify your build output directory
    baseDirectory: /docs
    files:
      - '**/*'
  cache:
    paths: []

I tried applying prod to ONLY master. I only want the prod mode to be applied and ran for the master. When I run the build.. dev branches shows unminified HTML and so does production. It is working and building but the prod mode is not being reflected in production so it is not executing my build prod command.

I searched online and also applied Environment variables AND followed this documentation which shows the build process "https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html" as follows:

enter image description here

Still is not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不疑不惑不回忆 2025-02-08 19:16:29

我遇到了类似的问题。我不确定这是最优雅的解决方案:

    build:
      commands:
        - if [ "${AWS_BRANCH}" = "master" ]; then echo "master branch"; npm run build; fi
        - if [ "${AWS_BRANCH}" = "dev" ]; then echo "dev branch"; npm run build -- --mode dev; fi

这对我使用,尽管我的堆栈与您的堆栈不同。它可能会导致您朝着正确的方向前进,或者帮助他人。

I ran into a similar problem. I'm not sure this is the most elegant solution:

    build:
      commands:
        - if [ "${AWS_BRANCH}" = "master" ]; then echo "master branch"; npm run build; fi
        - if [ "${AWS_BRANCH}" = "dev" ]; then echo "dev branch"; npm run build -- --mode dev; fi

This worked for me using, though my stack is different than yours. It might lead you in the right direction, or help others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文