如何压缩有/没有弹出create-react-app的构建。还将压缩文件包含在脚本标签中,并包含在index.html中 [英] How to compress build with/without ejecting create-react-app. Also include compressed file into script tag into index.html

查看:69
本文介绍了如何压缩有/没有弹出create-react-app的构建。还将压缩文件包含在脚本标签中,并包含在index.html中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-scripts build 进行生产准备就绪的构建并将其部署到AWS服务器上,我正在使用

GENERATE_SOURCEMAP =错误的纱线构建&& aws s3 sync build / s3:// *********




有什么办法应用gzip压缩来构建文件,并将gzip压缩的文件包含到index.html中,然后将其部署到aws上,以便在浏览器中提供gzip压缩的文件。

I'm using react-scripts build to make production ready build and to deploy it on AWS server I'm using

GENERATE_SOURCEMAP=false yarn build && aws s3 sync build/ s3://*********

Is there any way to apply gzip compression to build files and include gzipped files into index.html and deploy it on aws so that in browser gzipped files would be served.

推荐答案

更改cra的构建过程并不是一件容易的事,您可以将其弹出,但是之后必须自己创建。但是,在package.json中,您可以定义要在构建后启动的任务:

It's not really easy to change cra build process, you can eject it but you'll have to create your own after. But, in your package.json you can define a task to be launched after the build :

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "postbuild": "node yourNodeGzipScript.js"   }

希望它可以提供帮助。

这篇关于如何压缩有/没有弹出create-react-app的构建。还将压缩文件包含在脚本标签中,并包含在index.html中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆