简体   繁体   English

仅在 Amplify UI 中使用 Authenticator 时,如何减少 React App 中的包大小?

[英]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';

Here is my source map for the app:这是我的应用程序源地图: 在此处输入图像描述

package.json looks like this: package.json 看起来像这样: 在此处输入图像描述

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.

相关问题 如何进一步减少 React 应用程序的包大小 - How to reduce bundle size of react app even further 如何减小 React Leaflet 的包大小? - How do I reduce the bundle size of React Leaflet? 如何使用Webpack减少React的bundle.js文件大小 - How to reduce bundle.js file size of react using webpack 放大 UI 身份验证器组件 - Amplify UI Authenticator Component 当我将 create-react starter 与 typescript 一起使用时,如何仅创建一个 bundle js 文件? - How can I create only one bundle js file when I am using create-react starter with typescript? 用于打字稿问题的 AWS Amplify @aws-amplify/ui-react Authenticator 功能道具类型 - AWS Amplify @aws-amplify/ui-react Authenticator function prop types for typescript issues 使用 React 和 Ant Design Pro / UmiJS 实施 AWS Amplify Authenticator - Implement AWS Amplify Authenticator using React and Ant Design Pro / UmiJS 如何减少React应用程序的Webpack构建的捆绑包大小? - How to reduce bundle size of the webpack build for a react application? 如何减少 React Native 中的图像文件大小? - How can I reduce the image file size in react native? 如何减小 React-redux 代码的大小? - How I can reduce the size of the React-redux code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM