reactjs - Aws-Amplify:manifest.json 和 env.json 加载 index.html
问题描述
我正在构建的 React App 有一个 manifest.json 和一个 env.json,如下所示,
但是,当我使用 AWS-Amplify 将网站发布到 S3 存储桶时,manifest.json 和 env.json 会加载我的 index.html。一切都在 localhost 中正常工作,但在生产中我们遇到了上一个问题,即使我们可以获取其他文件作为图标和 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
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/**/*
看起来它正在为我们提供 index.html,因为它没有找到请求的文件,但我们不知道为什么会发生这种情况。
我们希望任何人都可以帮助我们解决这个问题。
解决方案
我可能已经找到了答案,为我工作。
所以我正在使用 React 和 React-router 构建一个单页应用程序 (SPA)。
我必须输入重定向规则来管理路由器的工作方式。根据放大文档。
Source address: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address: /index.html
Type: 200 (Rewrite)
似乎这也在推动manifest.json
去的请求index.html
我通过在我的放大控制台中添加另一个规则来解决这个问题:
Source address: /manifest.json
Target address: /manifest.json
Type: 200 (Rewrite)
有兴趣知道这是否适用于其他人。
推荐阅读
- javascript - 遍历两个数组,找出匹配的值
- python - 向 lambda 函数添加多个表达式,以获取 if/else 输出
- javascript - 如何以编程方式获取 YouTube 网址?
- python - 具有多处理功能的 Write():内置锁定以防止输出乱码?
- java - Java - Mockito - 如何在测试中将依赖注入抽象
- apache-spark - Spark SQL:从另一个数据帧中减去一个数据帧的相应行
- python-3.x - 写入 STATIC_ROOT 时,Django sqlite“数据库已锁定”
- c# - 粒子系统仅在 GetButton() 的开始和结束时播放
- jquery - 找到完全匹配文本的 CSS 选择器
- c# - Winforms - C# 任务栏进度指示器 (Windows 10)