我一直在使用我自己的手动解决方案(在 Webpack 之外)获取 SVG 文件的文件夹,提取 SVG 文件之间的内容<svg></svg>,构建一个 JSON 文件,然后使用它注入到 React 组件中,以便我可以输出特定的图标可以更好地控制周围的属性。
我遇到了https://github.com/gilesa/svg-to-json-webpack-plugin它实际上对我做了很多相同的事情,这太棒了!但是在尝试使用它时发生了一些奇怪的事情create-react-app,我怀疑是 Webpack 开发服务器。每当我尝试导入生成的.json文件时,开发服务器都会在浏览器中不断刷新。
我在我创建的问题中更详细地介绍了https://github.com/gilesa/svg-to-json-webpack-plugin/issues/1但我尝试调试到底是什么导致了无限循环还没有成功的。Webpack 插件 API 非常棒,所以我在此过程中学到了一些东西,但到目前为止还没有骰子。
理想情况下,如果这是导致观察者再次启动的原因,我希望 Webpack 忽略该特定文件。可能是因为它src正在寻找更改的同一目录中创建一个文件?感谢您在正确方向上的任何帮助!
学习玩笑和酶来测试 React 应用程序,使用 create-react-app 引导。
惩戒添加/ removeEventListener崩溃使用unmount后shallow,用在警告unmount后mount,见下文。有谁知道我做错了什么?
我的测试:
it('should add and remove resize event handler', () => {
const adder = jest
.spyOn(global, 'addEventListener')
.mockImplementation(() => {});
const remover = jest
.spyOn(global, 'removeEventListener')
.mockImplementation(() => {});
const wrapper = shallow(<App />);
// this seems to work
expect(adder).toHaveBeenCalled();
// causing issues
wrapper.unmount();
expect(remover).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
使用unmount后mount:
console.error node_modules/fbjs/lib/warning.js:33
Warning: Can only update a mounted or mounting component. This usually means …Run Code Online (Sandbox Code Playgroud) 我一直在学习 React 课程。下一步已经使用,npm run eject以便可以使用 css 模块。
由于弹出我不能使用 npm start。页面无法编译。出现一长串 linting 警告(实际上似乎来自 webpack 配置文件)。
我为这些文件和其他文件创建了一个 .eslintignore 文件:
./reactNotes.jsx
./nodeTest.js
./config
./scripts
Run Code Online (Sandbox Code Playgroud)
但是我的代码编辑器(vs 代码)或 webpack 似乎都没有注意到这个文件。eslint 是全局安装的。
我还研究了 eslint 的 webpack 配置,其中包含诸如 exclude 之类的选项:
{
test: /\.(js|jsx|mjs)$/,
enforce: 'pre',
use: [
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
exclude: /config/
}
Run Code Online (Sandbox Code Playgroud)
VS Code 在我的用户设置中启用了 eslint。
如何设置 webpack(甚至可能是 vs 代码)来忽略目录和文件?
更新:这里是.eslintrc:
{
"parser": "babel-eslint",
"extends": "react-app",
"plugins": [
"react",
"jsx-a11y",
"import"
],
"rules": …Run Code Online (Sandbox Code Playgroud) 当我create-react-app在 CLI 中运行时,我收到以下错误消息:
$ create-react-app udacity-goals-todo
internal/modules/cjs/loader.js:573
throw err;
^
Error: Cannot find module 'fs-extra'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/usr/local/lib/node_modules/create-react-app/createReactApp.js:40:12)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
Run Code Online (Sandbox Code Playgroud)
我试过卸载和重新安装create-react-app以及重新安装fs-extra.
关于如何重新启动和运行的任何想法?
我有一个用 create-react-app CLI 创建的 React 应用程序,突然sh.ext.stackdump在我的项目的根目录中出现了一个包含内容的文件
Stack trace:
Frame Function Args
0022CD28 008ABD26 (00000000, 0022CD84, 007F6D90, 00000000)
End of stack trace
Run Code Online (Sandbox Code Playgroud)
它是我的应用程序中需要的文件吗?如果我删除它会破坏吗?我应该保留它吗?为什么会出现?
我刚刚尝试使用 create-react-app (1.5.2) 引导一个新项目
create-react-app test-ts --scripts-version=react-scripts-ts
Run Code Online (Sandbox Code Playgroud)
没有接触任何东西,我“开始”,我得到以下信息:
<project root>/node_modules/@types/jest/index.d.ts
(23,13): Duplicate identifier 'beforeEach'.
Run Code Online (Sandbox Code Playgroud)
当我放
'skipLibCheck': true
Run Code Online (Sandbox Code Playgroud)
在 tsconfig.json 中,一切都可以毫无问题地转换。
我显然在另一台 ubuntu 机器上尝试过,它在没有 'skipLibCheck': true in tsconfig.json 的情况下工作得很好
我已经尝试过新版本的 node 和 npm,已经尝试过了
rm -rf ./node_modules
(npm|yarn) install
Run Code Online (Sandbox Code Playgroud)
错误仍然存在。你认为可能有什么问题?
这是我的 tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
},
"exclude": …Run Code Online (Sandbox Code Playgroud) 选项卡没有显示内容,这是代码。我该如何解决这个问题?
我究竟做错了什么?
这段代码几乎与 react-bootstrap 页面上的代码相似
//simple tabs.js
import React, {Component} from 'react';
import {Tabs, Tab} from 'react-bootstrap';
import TabItem from './TabItem';
import data from './data'
class SimpleTabs extends Component{
constructor(props){
super(props);
this.state = {
key: 1 | props.activeKey
}
this.handleSelect = this.handleSelect.bind(this);
}
handleSelect (key) {
console.log("selected " + key);
this.setState({key})
}
render(){
return (
<Tabs
activeKey={this.state.key}
onSelect={this.handleSelect}
id="controlled-tab-example"
>
<Tab eventKey={1} title="Tab 1">
Tab 1 content
</Tab>
<Tab eventKey={2} title="Tab 2">
Tab 2 content
</Tab>
<Tab eventKey={3} title="Tab …Run Code Online (Sandbox Code Playgroud)我创建了一个空的应用程序create-react-app。它在 pckage.json 和示例 App.test.js 中提供了一个测试脚本。第一步,我想根据create-react-app的文档设置测试环境。在我的应用程序中,我将使用 localStorage。让我们说一个像下面这样的动作要测试
export const cancel = () => {
localStorage.removeItem("MyAppData");
return { type: types.USER_CANCEL};
};
Run Code Online (Sandbox Code Playgroud)
除了酶部分,它显示了如何初始化localStorage. 所以我最终得到了一个setupTests.js文件
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
// react-testing-library renders your components to document.body,
// this will ensure they're removed after each test.
import "react-testing-library/cleanup-after-each";
// this adds jest-dom's custom assertions
import "jest-dom/extend-expect";
configure({ adapter: new Adapter() });
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
clear: jest.fn() …Run Code Online (Sandbox Code Playgroud) Create-react-app v2 使用 workbox cacheFirst 策略。我想使用 staleWhileRevalidate。如何创建自定义 Service Worker 并将其添加为现有应用程序?
create-react-app ×10
reactjs ×6
enzyme ×2
jestjs ×2
webpack ×2
eslint ×1
fs-extra ×1
git ×1
heroku ×1
javascript ×1
mobile ×1
typescript ×1
workbox ×1