我有一个前端 create-react-app 和一个使用 Expressjs 的后端 API。
我成功地将后端 API 部署到了 Google App Engine。
但是现在我需要将 create-react-app 部署到 Google Cloud 并且变得非常混乱,我尝试了一段时间的 google 并且没有正确/推荐的方法。
至少我看到其他人建议以两种方式进行:
使用谷歌云存储:
运行“npm run build”来创建“build”文件夹
将整个文件夹上传到存储桶中
=> 我发现使用这种方式有一个缺点:当我尝试重新加载页面 'url/aboutUs' 时,它没有找到。所以我必须回到“url”然后点击关于我们链接
=> 我猜我使用的 React Router 不能与 Google Cloud Storage 配合使用
=> 人们刚刚谈到使用它,但我找不到任何指南/教程。
那么将 create-react-app 部署到 Google Cloud 的推荐方法是什么?
你能提供一个教程吗?
谢谢。
google-app-engine google-cloud-storage reactjs google-cloud-platform create-react-app
在使用 create-react-app 构建或运行我的项目时遇到问题。它抛出js堆内存不足错误。
> yarn build
yarn run v1.6.0
$ react-scripts build
Creating an optimized production build...
<--- Last few GCs --->
[8792:0000021D06B28B70] 1492086 ms: Mark-sweep 1401.7 (1716.2) -> 1401.7 (1716.2) MB, 1474.4 / 0.0 ms allocation failure GC in old space requested
[8792:0000021D06B28B70] 1493542 ms: Mark-sweep 1401.7 (1716.2) -> 1401.5 (1658.7) MB, 1455.7 / 0.0 ms last resort GC in old space requested
[8792:0000021D06B28B70] 1494983 ms: Mark-sweep 1401.5 (1658.7) -> 1401.5 (1636.7) MB, 1439.7 / 0.0 ms last resort …Run Code Online (Sandbox Code Playgroud) 是否可以使用 Eslint 抛出错误而不是警告?我正在与 a 合作create-react-app并希望在我的团队中有一个非常严格的 lint 政策,并认为这可能是一个好的开始。
那可能吗?
是否可以create-react-app在我选择的某个浏览器中启动应用程序?目前,它总是在 Chrome 中运行,而我希望它在 Chrome Canary 中运行。有人知道吗?
我正在构建一个带有 React 前端的 Web 应用程序,由 golang api 层提供服务。我不经常使用 Javascript,所以我对 Node 构建系统不是很熟悉。有没有一种方法可以设置类似于 的脚本npm run build,但可以完整保留调试信息,以便我可以有效地使用浏览器调试器?
我在从create-react-app在 Windows 8.1 上创建的干净安装的应用程序运行 Jest 时遇到问题。安装后,运行命令npm run test,我收到错误:
No tests found related to files changed since last commit.
Running jest --watchAll,因此绕过 react-scripts,在同一目录中,虽然,显示:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do: …Run Code Online (Sandbox Code Playgroud) 我正在使用带有玩笑的酶并尝试打印出 wrapper.debug 但我没有得到像 jest 文档中所示的输出。这里有什么问题?我的测试文件:
import React from 'react';
import Enzyme, {shallow} from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import App from './../../components/App/App';
Enzyme.configure({ adapter : new EnzymeAdapter() });
it('should render without crashing', () => {
const wrapper = shallow(<App />)
console.log(wrapper.debug());
});
Run Code Online (Sandbox Code Playgroud)
我的控制台输出是这样的:
PASS src/test/integration/App.test.js
? Console
console.log src/test/integration/App.test.js:14
<ContextConsumer>
[function bound renderWrappedComponent]
</ContextConsumer>
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.8s
Ran all test suites related to changed files.
Run Code Online (Sandbox Code Playgroud) 我用“create react-app”创建了一个反应应用程序。
我现在正在尝试从 Reactstrap 添加导航栏。我从 Reactstrap(我将它添加为一个 React 组件)网站进行复制粘贴:
import React from 'react';
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem } from 'reactstrap';
export default class Example extends React.Component {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
this.state = {
isOpen: false
};
}
toggle() {
this.setState({
isOpen: !this.state.isOpen
});
}
render() {
return (
<div>
<Navbar color="light" light expand="md">
<NavbarBrand href="/">reactstrap</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink> …Run Code Online (Sandbox Code Playgroud) 我的文件夹中有一些图像,我尝试循环播放它。例如,一个名为“coupons”的文件夹有一些图像,如“coupon1.png”、“coupon2.png”、“coupon3.png”......然后在一个组件中,我尝试创建一个函数来导入所有图像并返回
<img src={coupon1} alt='coupon1' className="slide" />
<img src={coupon2} alt='coupon2' className="slide" />
<img src={coupon3} alt='coupon3' className="slide" />
.....
Run Code Online (Sandbox Code Playgroud)
我可以知道什么是一个好方法吗?如何避免一张一张导入图片?如何获取文件夹中图像文件的总数?
import coupon1 from '../assets/coupons/coupon1.png';
import coupon2 from '../assets/coupons/coupon2.png';
import coupon3 from '../assets/coupons/coupon3.png';
...
Run Code Online (Sandbox Code Playgroud)
以及如何循环它们?我尝试使用模板字符串,但它以字符串结尾而不是变量,所以仍然不起作用。太感谢了!
我对 React 和 React-router-dom 还很陌生。问题是,我试图在我的应用程序中为不同的路线获取不同的布局。但相反,不同路线的所有 css 文件都只是导入到一个巨大的冲突块中。
应用程序看起来像这样:
<Router>
< >
<Navigation />
<UpButton />
<Switch>
<Route path="/" exact component={Home} />
<Route path="/research" component={Research} />
<Route path="/publications" component={Publications} />
<Route path="/student" component={Student} />
<Route path="/about" component={About} />
</Switch>
</>
</Router>
Run Code Online (Sandbox Code Playgroud)
我渲染的每个组件如下所示:
import React from 'react';
import './home.scss';
// Utility
import Utility from 'components/utility/Utility';
class Home extends React.Component {
render() {
return (
< >
<Utility />
</>
);
}
}
export default Home;
Run Code Online (Sandbox Code Playgroud)
有没有办法只导入具有特定路由的特定CSS文件?就像 home.css 代表“/”路线,about.css 代表“/about”路线?
这可能是我的一个简单的误解,但我现在确实找不到任何解决方案。
create-react-app ×10
reactjs ×5
javascript ×4
jestjs ×2
babel-jest ×1
babeljs ×1
bootstrap-4 ×1
compilation ×1
css ×1
enzyme ×1
eslint ×1
heap-memory ×1
memory ×1
navbar ×1
node.js ×1
npm ×1
reactstrap ×1
size ×1
testing ×1
webpack ×1