当使用带有自定义反应脚本的create-react-app时,我总是最终安装了React 16(最新)。有没有办法使用旧版本(例如React 15)创建新项目?
我曾经create-react-app开始研究React应用程序.默认情况下,它使用服务工作者.我也碰巧用https为我的生产应用程序服务.
事实证明,使用此配置,我的浏览器只是没有获得我部署的新版本.它继续重新加载旧版本,即使我强制刷新.我可以通过检查页面(使用Chrome)来获取加载最新版本的唯一方法.然后,当我强制刷新时,加载最新的构建.
我已经禁用了服务工作者,因为它似乎是罪魁祸首,但我继续遇到这个问题.我不能要求我的用户在浏览器中打开检查器以获得最新版本.
我怎样才能找到解决这个问题的方法?有没有create-react-app配置我可以改变,以确保不再发生这种情况?
我console.log()在开发应用程序时使用了很多语句(我的意思是LOTS)。在没有Create React App 的情况下"ejecting",
我究竟如何才能删除它们
我考虑过但不确定如何实现:
在我的 package.json 中:
"build": "react-scripts build && uglifyjs --compress drop_console build/static/js/main.xxxxx.js -o build/static/js/main.xxxxx.js
Run Code Online (Sandbox Code Playgroud)
但是,我究竟如何知道文件的hash后缀,main.js以便我可以调用此命令并使用相同的文件名保存输出 js 文件
我正在开发一个应用程序,它将 create-react-app 与一个快速服务器(使用服务器渲染)连接起来。我指的是 this tutorial for it.To从服务器渲染文件,代码是
引导程序.js
require('ignore-styles');
require('babel-register')({
ignore:[/(node-modules)/],
presets:['es2015','react-app']
});
require('./index');
Run Code Online (Sandbox Code Playgroud)
索引.js
import express from 'express';
// we'll talk about this in a minute:
import serverRenderer from './middleware/renderer';
const PORT = 3000;
const path = require('path');
// initialize the application and create the routes
const app = express();
const router = express.Router();
// root (/) should always serve our server rendered page
router.use('^/$', serverRenderer);
// other static resources should just be served as they are
router.use(express.static(
path.resolve(__dirname, …Run Code Online (Sandbox Code Playgroud) 构建后我想要一个根文件夹中的配置文件(JSON)来配置我的应用程序。
像Translation和API Urls和...
我可以使用 create react app 来做到这一点吗?
我试图弄清楚如何使用不同的配置文件运行反应应用程序(通过create-react-app 创建)。
也就是说,假设我有多个环境(本地、开发、生产)并且我有一个指向后端(部署在另一台服务器上)的提取。
后端对每个环境都有自己的地址。我需要以某种方式为不同的发布设置全局变量。
例如,在 Springboot 中,这可以通过 application-"profile".properties 完成。
我通过 npm install -g serve & serve -s build 运行应用程序。怎么做?
我不知道如何在玩笑中模拟内部函数的返回值我尝试了不同的方法。最后我找到了这个答案, 但由于某种原因不值得嘲笑,这是示例:
国家.js
export const countryList = () => [
{
label: '+244',
value: 'Angola',
}, // list of all possible countries very long...
];
export const getSortedCountryData = intlLang =>
countriesList()
.sort((compare, comparable) =>
compare.value.localeCompare(comparable.value, intlLang, { sensitivity: 'base' }));
Run Code Online (Sandbox Code Playgroud)
国家.test.js
import * as countyListHelper from './countries';
describe('countries list', () => {
test('returns list of countries', () => {
const mockFn = jest.mock();
const expectedList = [
{
label: '+244',
value: 'Angola',
},
{
label: '+43',
value: 'Austria', …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用 create-react-app 引导的 React 应用程序,它在 Chrome 中运行良好,但我无法让它在 IE11 中运行。
启动应用程序后,我从控制台收到以下错误:
Object doesn't support property or method 'entries'
我花了好几个小时在谷歌上搜索,试图找到一个解决方案,但没有一个推荐的方法有效。
我尝试过的事情:
react-app-polyfill/ie11和react-app-polyfill/stable在顶部index.jscore-js/es/object/entries和core-js/features/object/entries在顶部index.jsindex.js:if (!Object.entries) {
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
Run Code Online (Sandbox Code Playgroud)
包.json:
{
"name": "ceas-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"auth0-js": …Run Code Online (Sandbox Code Playgroud) 我和我的团队使用 create-react-app bootstrap 命令启动一个新的 React 项目。我们在项目中添加了 eslint 部分,但我们遇到了以前从未发现过的恼人错误。当我们启动命令时
yarn run lint
Run Code Online (Sandbox Code Playgroud)
这里是 package.json:
{
"name": "name of the app",
"version": "0.1.0",
"private": true,
"dependencies": {
"jwt-decode": "^2.2.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-intl": "^3.12.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.5",
"redux-saga": "^1.1.3",
"reselect": "^4.0.0",
"styled-components": "^5.0.1"
},
"scripts": {
"analyze": "react-app-rewired build",
"build": "react-scripts build",
"cypress": "./node_modules/.bin/cypress open",
"eject": "react-scripts eject",
"lint:write": "eslint --debug src/ --fix",
"lint": "eslint --debug src/",
"prettier": "prettier --write src/*.tsx src/*.ts src/**/*.tsx src/**/*.ts src/**/**/*.tsx …Run Code Online (Sandbox Code Playgroud) 该ReactJS文档中阐明的我们可以使用
npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
创建一个 React 应用程序。但是我们如何更新create-react-app?如果它是由 开始的,是否有一般规则npx?我继续点击一些链接并到达网站https://create-react-app.dev/并且它有一行:
npm install react-scripts@latest
Run Code Online (Sandbox Code Playgroud)
但我想知道我是否运行它,它不是-g(全局),所以它可以让我们在任何文件夹中创建一个 React 应用程序吗?此外,当我运行它时,它给出了:
found 6289 vulnerabilities (4974 low, 306 moderate, 1004 high, 5 critical)
Run Code Online (Sandbox Code Playgroud)
所以似乎有一些需要额外做的事情。
create-react-app ×10
reactjs ×8
javascript ×3
babeljs ×1
core-js ×1
eslint ×1
express ×1
jestjs ×1
redux ×1
typescript ×1
uglifyjs ×1