javascript - React Deploying to AWS S3 production using npm - index.html 文件作为最后

标签 javascript reactjs amazon-s3 webpack create-react-app

我有一个 React 应用程序(使用 React Create App),我想使用脚本将其上传到生产环境。我的产品是 AWS S3 存储桶。我已经向 package.json 添加了一个“部署”脚本,如下所示:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "deploy": "aws s3 cp ./build s3://app.example.com --recursive --exclude \"*.DS_Store\" --cache-control public,max-age=604800 --profile production-profile"
  },

这会将所有构建文件上传到生产存储桶。由于构建静态文件(css、js 等)有自己的哈希码,因此它们不会被每个版本覆盖,这很好。

我遇到的问题是我不希望在其他文件完成上传之前上传 index.html 文件。这样,一旦 index.html 被最新版本覆盖,就会自动使用新的静态文件。

知道如何实现吗?如果有更好的脚本将 React 应用程序上传到 S3 会很棒。

最佳答案

您可以先复制除 index.html 之外的所有其他内容,然后再复制它。

 "aws s3 cp ./build s3://app.example.com --recursive --exclude \"*.DS_Store\" --exclude \"index.html\" --cache-control public,max-age=604800 --profile production-profile && aws s3 cp ./build/index.html s3://app.example.com  --cache-control public,max-age=604800 --profile production-profile "

关于javascript - React Deploying to AWS S3 production using npm - index.html 文件作为最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341141/

相关文章:

javascript - 脚本编辑器仅在编辑页面模式下工作

reactjs - 如何将用户转发到 react 中的其他页面/路径?

forms - 我正在使用 Amazon S3,并且想要创建一个在提交时发送电子邮件的表单。我怎样才能做到这一点?

amazon-web-services - AWS Kinesis 和 Lambda 数据版本控制

javascript - HTML5 音频 currentTime 属性并不总是相同的

javascript - 如何 Jest 模拟文件夹中的所有文件

javascript - 如何在 jQuery 中将图像添加为圆 Angular 的背景?

javascript - 如何设置react组件的iframe内容

javascript - React Hook "useState"在函数 "setResults"中调用,该函数既不是 React 函数组件也不是自定义 React Hook 函数

ruby-on-rails - 如何强制 send_data 在浏览器中下载文件?