[英]How can I reduce the bundle size in React App when only using Authenticator from Amplify UI?
I would like to use the Authenticator component from Amplify UI for sign in in my React App but doing so makes my apps bundle size huge;我想使用Amplify UI中的 Authenticator 组件登录我的 React 应用程序,但这样做会使我的应用程序包大小变得很大; it is currently 3Mb.它目前是 3Mb。 I have seen the discussion on reducing bundle size for Amplify more broadly which led to this release/blog which I have followed.我已经看到了关于减少Amplify 包大小的更广泛的讨论,这导致了我关注的这个版本/博客。 I am wondering if there is something similar I should be doing to import the Authenticator from Amplify UI in such a way that it does not import the entire ui-react library because it seems that is adding 1.8Mb to my app, most of which is coming from icons if I'm reading the chart right.我想知道我是否应该做类似的事情来从 Amplify UI 导入 Authenticator,这样它就不会导入整个 ui-react 库,因为它似乎给我的应用程序添加了 1.8Mb,其中大部分是如果我正确阅读图表,则来自图标。 I import the Authenticator as shown below:我导入 Authenticator,如下所示:
import { Authenticator } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
Authenticator 组件不会从其父目录导入任何内容,因此您可能只需从此处提取代码并安装任何缺少的依赖项。
Prior to version 2.12.0 we had some treeshaking issues in the @aws-amplify/ui-react
package which prevented the icons from being removed.在 2.12.0 版本之前,我们在@aws-amplify/ui-react
包中存在一些 treeshaking 问题,这些问题阻止了图标被删除。 This was fixed in version 2.12.0.这已在版本 2.12.0 中修复。 See CHANGELOG.请参阅变更日志。 It looks like you may be using 2.10.4.看起来您可能正在使用 2.10.4。 Can you make sure you are on the latest version?你能确定你使用的是最新版本吗?
npm install @aws-amplify/ui-react@latest
If you don't see a reduction in bundle size after upgrading the latest version that's a bug, and we would like to get it fixed.如果您在升级最新版本后没有看到包大小减少,这是一个错误,我们希望修复它。 You can either respond to this issue or even better would be to open a bug here .您可以对这个问题做出回应,或者更好的是在这里打开一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.