[英]How to deploy react js web app with all the components to Amazon Web Services amplify?
I am trying to deploy React.js web app on Amazon Web Services(AWS) amplify using git hub support.我正在尝试使用 git 集线器支持在 Amazon Web Services(AWS) 上部署 React.js web 应用程序。 It has been deployed and I got the url but the app doesn't look the same as it does when run locally.它已部署,我得到了 url,但该应用程序看起来与在本地运行时不同。
I have followed the steps given here .我已按照此处给出的步骤进行操作。
I have used the default build configuration settings and haven't changed anything.我使用了默认的构建配置设置并且没有改变任何东西。
Below is how it looks when run locally.以下是在本地运行时的外观。
Below is how it looks on the link provided by AWS amplify.下面是它在 AWS amplify 提供的链接上的外观。
Can anybody please point out what should I do differently?谁能指出我应该做些什么不同的事情? Do I need to configure something?我需要配置一些东西吗? I have used material-ui and react-bootstrap for frontend components.我已经将 material-ui 和 react-bootstrap 用于前端组件。
App.js - render function App.js - 渲染 function
render() {
return (
<div className={classes.container}>
<AppBar
className={classes.navbar}
style={{ backgroundColor: "transparent" }}
position="static"
>
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
>
<img alt="Logo" className={classes.logo} src={Logo} />
</IconButton>
<Typography variant="h6">TIP-TOP NX</Typography>
</Toolbar>
</AppBar>
<div className={classes.content}>
<div className={classes.frame}>
<Avatar style={{ margin: "auto", marginTop: "1em" }}>
<LockOutlined />
</Avatar>
<h3 style={{ color: "black", margin: "20px" }}>Sign in</h3>
<div
style={{
marginBottom: "3vh",
display: this.state.invalid ? "block" : "none",
}}
>
<Typography variant="h6" color="error">
Invalid details!
</Typography>
</div>
<TextField
fullWidth
required
label="Email"
variant="outlined"
error={this.state.errors.email.length > 0}
onChange={this.changeHandler("email")}
/>
<TextField
fullWidth
required
label="Password"
variant="outlined"
type="password"
error={this.state.errors.password.length > 0}
onChange={this.changeHandler("password")}
style={{ marginTop: "1em" }}
/>
<Button
onClick={this.submitHandler}
style={{ margin: "5vh auto" }}
variant="contained"
color="primary"
size="large"
>
Submit
</Button>
</div>
</div>
<footer className={classes.footer}>© 2020-2021</footer>
</div>
);
}
Linked css file:链接的 css 文件:
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
background: #555; /* fallback for old browsers */
background: -webkit-linear-gradient(
to right,
#555,
#000
); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #555, #000);
}
.logo {
height: 5vh;
border-radius: 50%;
margin-right: 1vw;
}
.navbar {
background-color: transparent;
color: white;
border-bottom: 1px solid white;
}
.active {
color: black;
background-color: white;
padding: 0.5em 1em 0.5em 1em;
font-size: 1.2em;
box-sizing: border-box;
opacity: 80%;
}
.content {
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 90vh;
text-align: center;
box-sizing: border-box;
}
.frame {
background-color: #e0e0e0;
width: 30%;
height: auto;
opacity: 80%;
padding: 20px;
margin: 20px;
box-sizing: border-box;
border: 2px white solid;
color: black;
}
.footer {
color: white;
text-align: center;
border-top: 1px solid white;
height: 10vh;
display: flex;
align-items: center;
justify-content: center;
}
@media only screen and (max-width: 1000px) {
.frame {
width: 50%;
}
}
The problem is happening due to a bug in cssnano package used by react to minify your CSS file during the build.问题是由于 cssnano package 中的一个错误而发生的,该错误在构建期间被 react 用于缩小 CSS 文件。 The issue is still happening as of today (December 2020).截至今天(2020 年 12 月),该问题仍在发生。
The minified version of the CSS file will convert any value in percentages (xx%) to 1% during the build, that's why you don't see it in development because you're using the normal (non-minified) version of the CSS file while in development. CSS 文件的缩小版本将在构建期间将任何百分比(xx%)值转换为 1%,这就是为什么您在开发中看不到它,因为您使用的是 CSS 的正常(非缩小)版本开发中的文件。
The quick fix to this problem is to actually not use any % values on CSS, instead use decimals (0.xx) and your app should work just fine.这个问题的快速解决方法是实际上不在CSS 上使用任何 % 值,而是使用小数(0.xx) ,您的应用程序应该可以正常工作。
There's a pull regarding this issue on Github, you can check it out here on cssnano repo在 Github 上有一个关于这个问题的拉动,你可以在cssnano repo上查看它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.