我正试图弄清楚如何使用React-Intl更改语言.这是我的第一个React App,它是用create-react-app制作的,我没有使用Redux和Flux.
在我的index.js中,我有以下代码:
import React from 'react';
import ReactDOM from 'react-dom';
import TodoApp from './components/TodoApp';
import registerServiceWorker from './registerServiceWorker';
import './index.css';
// Bootstrap CSS libraries
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import { IntlProvider, addLocaleData } from 'react-intl';
import intlEN from 'react-intl/locale-data/en';
import intlES from 'react-intl/locale-data/es';
import intlMessagesES from './i18n/locales/es.json';
import intlMessagesEN from './i18n/locales/en.json';
addLocaleData([...intlEN, ...intlES]);
/* Define your translations */
let i18nConfig = {
locale: 'es',
messages: intlMessagesES
};
let changeLanguage = (lang) => {
i18nConfig = { locale: lang, messages: …Run Code Online (Sandbox Code Playgroud) 我已经成功地为我的React应用程序提供了index.html文件,但是在我的第一个React组件的html文件index.js中替换<root>它并没有触发ReactDOM.render.
如何index.js启动文件?如果我对React应用程序服务的理解在某些方面存在偏差,我将非常感谢您的澄清.
server.jsindex.htmlmain.[hash].js- 似乎是index.js包含ReactDOM.renderfor my React应用程序的缩小版本// server.js
let app = express();
app.use(express.static(path.join(__dirname, '../client/public')));
Run Code Online (Sandbox Code Playgroud)
这会成功加载create-react-app提供的默认index.html
// index.html
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
上面的代码部分可能/可能没用,但它是create-react-app附带的默认html文件.我是否需要使用引用缩小index.js
文件的脚本标记替换noscript标记?我试过了,并没有改变,但也许是因为不正确的相对路径制作.
我正在使用create-react-app构建一个react项目,并试图找出如何将我的代码部署到Siteground上的托管服务器.
有谁知道最好的方法吗?我是否通过FTP导入我的构建文件夹?我可以通过GitHub自动化流程吗?
提前致谢!
github web-deployment continuous-deployment reactjs create-react-app
我正在使用creat-react-app(CRA),只是想通过CSS将放置在公共文件夹中的png文件包括在内(我将所有图像文件保存在此)。现在,我尝试通过CSS引用此图像(我仅将background-image行添加到了新生成的CRA应用中):
.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
background-image: url("../public/example.png");
}
Run Code Online (Sandbox Code Playgroud)
You attempted to import example.png which falls outside of the project src/ directory
如何在CSS文件中引用图像文件而不在其中复制内容/src?我也不想弹出应用程序并摆脱错误消息。
编辑:此问题不同于src目录外部的create-react-app导入限制,因为它没有显示如何在CSS级别解决此问题。建议的解决方案是在我不想执行的JavaScript文件中添加样式。
我有一个使用Create-React-App(react-scripts)和Material-UI的React App.我想为我的应用程序应用强大的内容安全策略,它不允许不安全的内联样式.
我想在CSP-Header服务器端设置nonce存在,这可以很容易地完成.但是,Material-UI <style>在运行时动态设置某些内联标记,而不使用nonce值作为属性.
我在指南和csp下看到了Material-UI网站上的文档.他们似乎提供了一个解决方案.但是,该解决方案是用于HTML的服务器端呈现,我没有使用它.我正在使用Create-React-App并静态地提供HTML,CSS和JavaScript.
有谁知道如何实现这一目标?
content-security-policy reactjs material-ui create-react-app
我有一个使用Create-React-App创建的项目.我希望添加一个precommit钩子来运行我们的linter并测试pre-commit包.
"pre-commit": [
"precommit-msg",
"lint",
"test"
],
Run Code Online (Sandbox Code Playgroud)
但是,由于测试脚本默认在监视模式下运行,因此可以防止提交实际发生.如何在预提交中添加不在监视中移动的测试?
我一直在使用 create-react-app 和我添加的其他一些库开发一个小应用程序。鉴于计划的架构和一些我想用 react-router 运行的测试,我希望能够使用 url 中的域 mame 在本地运行我的应用程序,这样而不是
本地主机:3000/
这将是
somedomain.com
我已经尝试了一些事情,比如弹出 ceate-react-app 但我不知道如何修改 webpack 配置来改变公共路径,或者如何在我的机器上设置某种代理,这样 somedomain.com 就相当于输入本地主机:3000
我不确定正确的方法是什么,我似乎还找不到任何可靠的信息。
我正在尝试使用react CDN脚本测试我的React应用程序(使用create-react-app创建)的性能,并且我做了'npm run弹出'添加webpack外部依赖关系react和react-dom。
我这样做,很容易在的WebPack配置和<script>在index.html
...
externals: {
react: 'React',
'react-dom':'ReactDOM'
},
...
Run Code Online (Sandbox Code Playgroud)
现在,我想将其还原到以前的状态,
我正在使用git,并且在单独的分支中进行了此实验。
我跑了git checkout master,npm start
结果很烦人
> myapp@0.18.1 start /home/code/serverSync/myapp/ui
> react-scripts start
sh: 1: react-scripts: not found
npm ERR! Linux 4.15.0-23-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用创建一个新的反应应用程序
create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误.我之前使用过create-react-app,这是我第一次遇到这个
Creating a new React app in C:\Users\jason\Desktop\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! code E401
npm ERR! 401 Unauthorized: @babel/core@7.1.0
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jason\AppData\Roaming\npm-cache\_logs\2018-11-28T04_38_50_180Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts
has failed.
Deleting generated file... package.json
Deleting my-app/ from C:\Users\jason\Desktop
Done.
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误日志
0 info it worked if it ends with …Run Code Online (Sandbox Code Playgroud) 这对我来说很难做到正确。通过Google进行指导的方式很少。我希望这对其他人有帮助。
正如Dan Cornilescu所指出的,管理人员接受第一场比赛。因此,我们从更具体到更具体。我已经按照以下步骤创建的文件夹结构解决了这个问题npm run build:1.处理js,css和media的子目录。2.处理对manifest.json和fav.ico的json和ico请求。3.将所有其他流量路由到index.html。
handlers:
- url: /static/js/(.*)
static_files: build/static/js/\1
upload: build/static/js/(.*)
- url: /static/css/(.*)
static_files: build/static/css/\1
upload: build/static/css/(.*)
- url: /static/media/(.*)
static_files: build/static/media/\1
upload: build/static/media/(.*)
- url: /(.*\.(json|ico))$
static_files: build/\1
upload: build/.*\.(json|ico)$
- url: /
static_files: build/index.html
upload: build/index.html
- url: /.*
static_files: build/index.html
upload: build/index.html
Run Code Online (Sandbox Code Playgroud)
欢迎提供更有效的答案。
原始问题:
为反应路由器路由设置GAE app.yaml会产生“意外令牌<”错误。
在开发环境中,所有路径都可以在直接调用时起作用。localhost:5000和localhost:5000 / test产生预期的结果。
在GAE标准app.yaml中,当直接调用URL www.test-app.com时,该函数用于根目录。 www.test-app.com/test会产生404错误。
app.yaml #1
runtime: nodejs8
instance_class: F1
automatic_scaling:
max_instances: 1
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
Run Code Online (Sandbox Code Playgroud)
对于所有路径,将app.yaml配置为接受通配符路由失败。www.test-app.com/和www.test-app.com/test产生错误“意外令牌<”。看来它正在将.js文件作为index.html提供。
app.yaml …Run Code Online (Sandbox Code Playgroud) google-app-engine app.yaml google-cloud-platform react-router create-react-app
create-react-app ×10
reactjs ×9
app.yaml ×1
ecmascript-6 ×1
express ×1
githooks ×1
github ×1
javascript ×1
jestjs ×1
material-ui ×1
node.js ×1
npm ×1
proxy ×1
react-intl ×1
react-router ×1
server ×1
static ×1
testing ×1
webpack ×1