我正在尝试创建一个React-Redux库,我正在尝试使用create-react-app来获取样板代码,但它在构建脚本中包含了与appHtml无关的内容.
有没有办法将弹出的create-react-app转换为库 - 特别是我需要不将所有js文件打包成一个,而只是通过babel传递它们并为每个React组件生成单独的文件?
我有一些背景图片没有加载困难.我对初始创建反应应用程序做了一些重大修改,我的文件夹结构现在如下:
注意:我省略了一些文件和文件夹,如果您需要更多请告诉我.
App/
node_modules/
src/
client/
build/
node_modules/
public/
src/
css/
App.css
images/
tree.png
yeti.png
App.jsx
server/
package.json
Procfile
Run Code Online (Sandbox Code Playgroud)
以下是我创建此问题的步骤:
$ cd src/server && npm run dev
Run Code Online (Sandbox Code Playgroud)
这将启动开发服务器并打开浏览器到我的应用程序,一切正常,除了页面上的一些元素没有显示图像.
注意:我加载图片yeti.png,这很好.
App.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import './css/App.css';
import yeti from './images/yeti.png';
const Footer = function(props) {
return (
<div>
<Yeti />
<Trees />
</div>
);
};
const Yeti = function(props) {
return (
<img
src={yeti}
className="yeti yeti--xs"
alt="Yeti"
/>
);
};
const Trees = function(props) …Run Code Online (Sandbox Code Playgroud) 我正在写与生成的应用程序create-react-app有redux,react-redux和react-router.每当我点击Link这样的话:
import React from 'react'
import { Link } from 'react-router'
import ThingCard from '../../components/ThingCard'
const ThingsList = ({things}) => {
return (
<ul>
{things.map(thing =>
<Link to={"/things/"+thing.id} key={thing.id}><ThingCard thing={thing}/></Link>
)}
</ul>
)
}
export default ThingsList
Run Code Online (Sandbox Code Playgroud)
我在控制台中看到以下警告.我不知道他们来自哪里或者他们的意思.谷歌搜索没有产生任何有用的结果.是否可以安全地忽略这些警告,如果不能,我怎样才能更多地了解它们?我相信这个问题阻止了父页面呈现它的孩子.
我已禁用所有网络请求.
编辑:此错误仅显示在Chrome Canary而不是Google Chrome中.但是,Google Chrome无法正确呈现孩子(可能是由于此问题)
我是React的新手,我正在寻找React等效的JQuery方法,在我的应用程序中包含分析.
通常我会:
在html页面上包含第三方库.很容易进入index.html页面,但我不知道这是否是最佳做法.
<script src="http://path/to/script/utag.js" />
然后我可以与库交互,只要它已经加载,我可以使用JQuery window.load验证.这个脚本在普通的html页面上运行正常,但我试图在我的反应应用程序中找到相同的最佳实践方法.我不想介绍jquery,目前我的React容器会告诉我,如果我尝试utag在函数中引用,那么utag没有定义.
<script>
$(window).load(function() {
utag.link({ "event_name" : "locale_select", "language" :
utag_data.language, "currency" : utag_data.currency } );
});
</script>
我是React的新手,所以任何帮助都会很棒.我知道我的项目没有使用webpack,它使用的是react-scripts并且是使用create-react-app实用程序启动的.
我已经从Create-React-App库创建了一个示例应用程序.当我运行build命令时,它会使用cache-first策略自行生成一个service-worker .但我需要更多功能,比如缓存一些API响应.我不知道如何在自动生成的service-worker中修改包含我自己的代码的脚本.我已经为我的案例找到了一些帮助热线,但这些还不足以全面了解它.
默认情况下,生成的服务工作文件不会拦截或缓存任何跨源流量,如HTTP API请求,图像或从其他域加载的嵌入.如果要对这些请求使用运行时缓存策略,可以弹出然后在webpack.config.prod.js的SWPrecacheWebpackPlugin部分中配置runtimeCaching选项.
以上段落来自官方文件
提前致谢!
我在create-react-app项目中使用Semantic-UI.我使用自定义主题使用ThemeProvider修改单个组件,这是很好的.但是,我试图弄清楚如何修改较少的变量,如semantic-ui文档中所述
该反应语义UI文档中并没有提供太多这一点.有什么建议吗?
我的Index.js看起来大致如下:
import 'semantic-ui-css/semantic.min.css'
import { ThemeProvider } from 'styled-components'
import mainTheme from './themes/mainTheme'
ReactDOM.render(
<ThemeProvider theme={mainTheme}>
<App />
</ThemeProvider>
document.getElementById('root')
)
Run Code Online (Sandbox Code Playgroud)
编辑:具体到我想要实现的目标,我想改变使用的主要字体.
我只是将一个应用从移植create-react-app-typescript到create-react-app。在结构相同但不同的应用程序中,我执行了相同的步骤。
npm uninstall react-scripts-ts
npm install react-scripts
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
Run Code Online (Sandbox Code Playgroud)
src/react-app-env.d.tsThe generated file src/react-app-env.d.ts causes the --isolatedModules error.
How do I prevent react-scripts from generating the src/react-app-env.d.ts file upon react-scripts start?
我正在尝试安装tailwindcss并在全新的CRA 2.0(特别是2.1.2)中使用打字稿。
我无法在没有CRA覆盖的情况下覆盖“ isolatedModules”:true标志。
我尝试通过从modules.export更改导出样式并将配置强制为false而不是删除它来解决此问题。我读到,您还可以创建一个单独的tsconfig.json,扩展您的旧tsconfig.json并覆盖那里的更改,但这似乎很麻烦。
tsconfig.json
{
"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,
"noEmit": true,
"jsx": "preserve",
"isolatedModules": true
},
"include": [
"src",
"postcss.config.js"
]
}
Run Code Online (Sandbox Code Playgroud)
postcss.config.json
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [tailwindcss('./tailwind.config.js'), require('autoprefixer')]
};
Run Code Online (Sandbox Code Playgroud)
这是我的npm开始吐出来的东西
The following changes are being made to your tsconfig.json file:
- compilerOptions.isolatedModules must be true (implementation limitation)
Run Code Online (Sandbox Code Playgroud)
我可以看到我的应用程序可以编译,工作,然后绘制到页面上,然后将其替换为显示错误的红色错误框
Type …Run Code Online (Sandbox Code Playgroud) 我使用Create React App创建了一个应用程序。
如何添加resetDatabase()可从Chrome调试控制台(或其他方式)调用的全局调试功能(例如)?
我通过此命令使用react@17.0.2和创建了一个新的 React-typescript 应用程序typescript@4.5.2:
npx create-react-app my-app --template typescript
然后我决定像之前多次那样定义别名路径。我tsconfig.paths.json在我的应用程序的根目录中创建了 。
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"components/*": ["/components/*"],
"routes/*": ["/routes/*"],
"constants/*": ["/constants/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将extend属性添加到文件中tsconfig.json:
{
"extends": "./tsconfig.paths.json",
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src" …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×8
javascript ×3
typescript ×3
alias ×1
debugging ×1
ecmascript-6 ×1
jsx ×1
react-router ×1
redux ×1
sw-precache ×1
tailwind-css ×1