我知道我们可以在生产模式下测试我们的 Service Worker,但是重新构建和部署的过程非常烦人。有什么方法可以在开发模式下启用服务工作者吗?
reactjs service-worker progressive-web-apps create-react-app
我正在开发一个 Wordpress“小部件”,它将是一个小型反应应用程序。为此,我选择了create-react-app 。
现在我可以了解如何足够轻松地独立运行开发服务器,但我想在它位于 WordPress 网站内时对其进行开发。我创建了一个简单的“自定义 HTML”小部件:
<div id="root"></div>
<script type="text/javascript" src="http://localhost:8080/static/js/bundle.js"></script>
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用......
注意:我是/static/js/bundle.js通过直接加载时查看网络选项卡中的请求来想到的http://localhost:8080,这是访问应用程序的开发版本的规定方式。
那么,当嵌入到我的本地版本的 WordPress 网站时,如何访问应用程序的开发版本(具有所有实时重新加载的优点)?
我最近开始进行网络开发。我陷入了困境,这可能是一个微不足道的问题。我试图弄清楚如何将数据从动态创建的数据传递index.html到我的(打字稿)反应前端(通过创建create-react-app)。
假设我们有一个 Flask Web 服务器,当请求“/”资源时,它会收集一些初始用户数据,用它实例化一个页面模板并返回该页面:
# flask webserver
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
initial_user_data = {"foo":"bar",
"baz":"biz"}
return render_template('index.html', initial_data=initial_user_data)
if __name__ == '__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
为了简单起见,initial_user_data在这里存储硬编码数据。在我的实际用例中,字典中填充了从文件等读取的各种特定于用户的数据项。
接下来,我们假设index.html使用initial_data.
<!DOCTYPE html>
<html lang="en">
<head>
...
<title>React App</title>
</head>
<body>
<script>
initial_data = {{initial_data | tojson}}
console.log(initial_data)
</script>
<div id="root"></div>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我们现在启动网络服务器并打开浏览器导航到该页面时,可以看到正在initial_data记录到浏览器的控制台输出。到目前为止,一切都很好。
现在我的问题是:如何传递initial_data给我的(打字稿)反应组件?从概念上讲,我想做这样的事情:
// App.tsx
import React from …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Nginx 作为反向代理来为两个容器提供服务。这是我的 Nginx conf 文件的一部分:
upstream dashboard {
server dashboard:80;
}
upstream editor {
server editor:80;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://dashboard;
}
location /editor/ {
rewrite ^/editor(.*)$ $1 break;
proxy_pass http://editor;
}
Run Code Online (Sandbox Code Playgroud)
当我导航到浏览器中的 url 时,我收到 404 错误/editor,因为该页面正在提交对驻留在上游容器“editor”中的静态资源的请求。
我对 Nginx 还很陌生,但我推测当它收到带有 url 的请求时:
http://example.com/static/css/2.3d394414.chunk.css
Nginx 无法知道相应的 css 位于editor容器内部。我该如何修改配置来解决这个问题?我已经看到一些配置为任何静态资产提供了通用路径,但我需要一个可以处理 docker 容器内资产的解决方案。
我已经使用“create-react-app”创建了一个React应用程序,并且它通过“npm start”运行良好,但是,当我尝试构建或部署到Heroku时,我从react-scripts build.js中收到一个错误,日志如下:
-----> Build
Running build
> areaos-react@0.1.0 build /tmp/build_b6b622a1f46daa3af2d16fdb6ffb259a
> react-scripts build
Creating an optimized production build...
Failed to compile.
Parse error on line 1:
0.3(-1)
---^
Expecting end of input, "ADD", "SUB", "MUL", "DIV", got unexpected "LPAREN"
Run Code Online (Sandbox Code Playgroud)
我尝试过: -更新npm模块,包括react-scripts -从package.json中删除“react-scripts build” -将package.json中的“main”更改为“react-scripts start”
这是我的 package.json
{
"name": "doggos-react",
"version": "0.1.0",
"engines": {
"node": "8.9.3",
"npm": "6.9.0"
},
"private": true,
"dependencies": {
"caniuse-lite": "^1.0.30000989",
"chart.js": "^2.8.0",
"chartjs-plugin-labels": "^1.1.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"gl-react": "^3.17.2",
"glsl-fxaa": "^3.0.0",
"glslify": "^7.0.0", …Run Code Online (Sandbox Code Playgroud) 我们的公司安全策略设置为开发人员需要使用单独的帐户来运行非白名单程序,但这些帐户无法访问互联网,因此当我尝试运行 create-react-app 时,它无法下载任何文件。
是否可以使用我可以访问互联网的普通帐户预先下载必要的文件,然后使用这些文件离线运行 create-react-app ?
我试图了解如何让 PDF Kit 在 React JS 中工作。
我的简单要求是使用 ReactJS 和 PDFKit 在浏览器中渲染文件。
查看教程,参考了 PDFKit 可以在浏览器中工作的一些选项,但是尚不清楚这将如何应用于 React JS 的世界,特别是基于 Create React App 的项目......
http://pdfkit.org/demo/browser.html
https://www.npmjs.com/package/pdfkit#browser-usage
有没有人遇到过基于 React JS 和 PDFKit 的 Create React App 的工作示例?
谷歌今晚似乎没有给出答案。
我正在尝试将 eslint 添加到我的打字稿create-react-app应用程序中。我正在使用 Visual Studio 代码。
我做了:
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
Run Code Online (Sandbox Code Playgroud)
.eslintrc如下所示的文件{
"plugins": [
"react"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"settings": {
"import/resolver": {
"node": {},
"babel-module": {
"root": ["./src"]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我尝试做一些 linting 问题,例如尾随空格或不是 pascalCase,但我从未收到 Eslint 的警告,我只看到打字稿错误,但从未看到类似的 linting 问题。
是否需要进行一些额外的配置才能使其在我的工作区上运行?
我将 RCA 与react-rewired 包装器一起使用。为了向 webpack 添加自定义配置,我创建了config-overrides.js存储配置设置的文件。我添加了一个babel-plugin-import,这非常简单。但现在我想moment-locales-webpack-plugin在我的应用程序中仅配置一种区域设置以减少应用程序的重量。
const { override, fixBabelImports, addWebpackPlugin } = require('customize-cra');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
}),
addWebpackPlugin(MomentLocalesPlugin, { localeToKeep: ['us'] }),
);
Run Code Online (Sandbox Code Playgroud)
之后yarn start它向我展示:
编译失败。
MomentLocalesPlugin: received unknown options: _pluginCompat, hooks, name, parentCompilation, outputPath, outputFileSystem, inputFileSystem, recordsInputPath, recordsOutputPath, records, removedFiles, fileTimestamps, contextT
imestamps, resolverFactory, infrastructureLogger, resolvers, options, context, requestShortener, running, watchMode, _assetEmittingSourceCache, _assetEmittingWrittenFiles, watchFileSystem. Only `localesToKeep` and `ignoreInva
lidLocales` options …Run Code Online (Sandbox Code Playgroud) 我正在使用 create-react-app 的 TypeScript 风格:
npx create-react-app my-app --typescript
Run Code Online (Sandbox Code Playgroud)
当我构建应用程序时,捆绑包仍然包含 ES5 后的代码,例如 Symbol。我缺少什么?我的 tsconfig 文件:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×6
typescript ×3
babeljs ×1
docker ×1
ecmascript-5 ×1
embed ×1
eslint ×1
heroku ×1
javascript ×1
nginx ×1
node.js ×1
pdfkit ×1
webpack ×1