【问题标题】:React source code exposed in AWS amplify deployment在 AWS 放大部署中公开的 React 源代码
【发布时间】:2021-06-25 00:38:06
【问题描述】:

我正在测试在 AWS amplify 上部署应用程序。这些是我遵循的步骤:

  1. 创建了一个示例 create-react-app(此处称为 deploy_test 应用),
  2. 将代码推送到 GitHub 存储库
  3. AWS Amplify 控制台 > 部署应用程序 > 链接的 GitHub 存储库 > 使用默认配置(如下所示)
version: 1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

即使我推送新的更改,部署也能正常运行。问题是我可以在 Chrome 开发工具中看到整个源代码(如下所示)。有关如何解决此问题的任何提示?

【问题讨论】:

    标签: reactjs amazon-web-services web-deployment aws-amplify


    【解决方案1】:

    默认情况下,create-react-app 会生成完整的源图:

    用于捆绑 JS、CSS 和用于生产的图像的构建脚本,带有散列和源映射。 https://github.com/facebook/create-react-app#whats-included

    你可以在构建脚本之前设置GENERATE_SOURCEMAP=false

        build:
          commands:
            - GENERATE_SOURCEMAP=false yarn run build
    

    你可以在create-react-app webpack config的源码中看到它的定义:

    https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js#L43-L46

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2015-10-19
      • 2018-06-12
      • 2016-04-08
      • 2016-07-10
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多