Aws-Amplify:manifest.json 和 env.json 加载 index.html

Rub*_*ary 3 reactjs aws-amplify

我正在构建的React应用程序有一个manifest.json和一个env.json,如下所示,

但是,当我使用 AWS-Amplify 将网站发布到 S3 存储桶时,manifest.json 和 env.json 会加载我的 index.html。一切都在本地主机中正常工作,但在生产中我们遇到了上一个问题,即使我们可以获取其他文件作为图标和 robots.txt。

我们的公共文件夹的内容如下:

asset-manifest.json
browserconfig.xml
ec4c4f981671b5dee24ab5f541f07720.png
ef7c6637c68f269a882e73bcb57a7f6a.woff2
env.json <----- loading index.html
icons
index.html
main-5fbcf0b95e5bf6891f54.js
main-5fbcf0b95e5bf6891f54.js.LICENSE.txt
manifest.json. <----- loading index.html
robots.txt.   <------ working
service-worker.js
Run Code Online (Sandbox Code Playgroud)

amplify.yml 文件如下所示:

 version: 0.1
frontend:
  phases:
    preBuild:
      commands:
        - npm install
    build:
      commands:
        - NODE_ENV=$MY_ENV_SELECTOR node ./node_modules/webpack/bin/webpack.js --mode production --env=prod 
  artifacts:
    baseDirectory: dist
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
Run Code Online (Sandbox Code Playgroud)

看起来它正在为我们提供index.html,因为它没有找到所请求的文件,但我们不知道为什么会发生这种情况。

我们希望任何人都可以帮助我们解决这个问题。

Ber*_*uts 5

我可能已经找到了答案,为我工作。

所以我正在使用 React 和 React-router 构建一个单页应用程序(SPA)。

我必须输入重定向规则来管理路由器的工作方式。根据放大文档。

Source address: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address: /index.html
Type: 200 (Rewrite)
Run Code Online (Sandbox Code Playgroud)

manifest.json看来这也在推动去的请求index.html

我通过在放大控制台中添加另一条规则解决了这个问题:

Source address: /manifest.json
Target address: /manifest.json  
Type: 200 (Rewrite)
Run Code Online (Sandbox Code Playgroud)

有兴趣知道这是否适用于其他人。