reactjs - 使用 cra 在反应中排序顺序导入
问题描述
我正在尝试更新我的项目配置以对导入顺序进行排序。我正在使用create-react-app
,并且一直按照本文中的说明进行操作。这是我到目前为止所做的:
- 运行
yarn add eslint-plugin-import -D
。 - 在我的应用程序的 src 文件夹中添加了一个 .eslintrc.js。
- 添加了文章中提到的以下配置:
module.exports = {
extends: "react-app",
plugins: ["eslint-plugin-import"],
"import/order": [
"error",
{
groups: ["builtin", "external", "internal"],
pathGroups: [
{
pattern: "react",
group: "external",
position: "before",
},
],
pathGroupsExcludedImportTypes: ["react"],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
};
我编写了以下示例组件并更改了import
语句的顺序以检查这是否有效,但是当我保存时,顺序没有被更新:
示例.js
import { PropTypes } from "prop-types";
import React from "react";
const Sample = () => <div>Hello</div>;
export default Sample;
保存后预计
示例.js
import React from "react";
import { PropTypes } from "prop-types";
const Sample = () => <div>Hello</div>;
export default Sample;
我也试过simple-import-sort
了,不知道怎么配置。如何配置我的项目以便import
语句自动保持有序?
解决方案
推荐阅读
- c# - 如何通过 Twilio 中提供的任何 Message 属性区分 MMS 和 SMS
- azure - 还原 azure webapp 中的更改
- c# - 如何重构这一系列 null 或空字符串测试,使其更小更干净?
- ios - FirebaseInstanceID 文件未找到目标 c
- python - 透明图像覆盖具有主窗口背景颜色的框架
- c# - 使用表存储时 Azure Key Vault 大容量 KeyUnwrap 操作
- python - 从 django 中的子模型表单填充父模型
- javascript - 用 babel 问题配置 jest - “找不到模块”错误
- audio - 使用 pydub 更改 BPM
- javascript - 如何通过 cdn 脚本注册 service worker。如何使用外部 url 注册 service worker