Skip to content

Commit 7064737

Browse files
committed
feat: react-dev-inspector 替换为 code-inspector-plugin
1 parent 0b4832e commit 7064737

9 files changed

Lines changed: 178 additions & 1001 deletions

File tree

README.en-US.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pnpm build:pro
5858
- **Global State Management**: Provides Zustand global state management example code, simplifying cross-component state sharing and improving development efficiency. (See [store](./src/store))
5959
- **Axios Request Encapsulation**: Encapsulated Axios to uniformly handle HTTP requests and responses, simplifying interaction with backend interfaces. (See [services](./src/services))
6060
- **Utility Functions & Hooks**: Provides some convenient and practical utility functions and hooks. (See [utils](./src/utils), [hooks](./src/hooks))
61-
- **react-dev-inspector Integration**: Click on page elements to open corresponding code in IDE, facilitating code debugging and improving development efficiency. (See [vite.config.ts](./vite.config.ts))
6261
- **Automatic Import Order Beautification**: Integrated prettier-plugin-sort-imports plugin to automatically beautify import order, enhancing code readability and maintainability.
6362
- **Others**: Provides commands for convenient environment-based running and building; configured code splitting strategy; local reverse proxy for CORS; and detailed `nanny-level comments`, etc.
6463

@@ -122,12 +121,6 @@ pnpm build:pro
122121
- Unified commit message standards (Commitlint + Husky)
123122
- Automatic code formatting to ensure team code style consistency
124123

125-
### 🔧 Powerful Development Toolchain
126-
127-
- react-dev-inspector integration - click page elements to jump directly to source code
128-
- Automatic import order sorting for improved code readability
129-
- Multi-environment configuration (dev/test/pro) to meet different deployment requirements
130-
131124
## 📦 About Route Caching (keep-alive)
132125

133126
> React officially hasn't implemented functionality similar to Vue's \<keep-alive\>. React team rejected adding this feature based on two considerations, which you can search and read about. To achieve state preservation, the official team recommends these two manual state preservation methods:

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pnpm build:pro
6262
- **全局状态管理**:提供了 Zustand 全局状态管理示例代码,简化跨组件状态共享,提升开发效率。(详见`store`
6363
- **Axios 请求封装**:对 Axios 进行封装,统一处理 HTTP 请求和响应,简化与后端接口的交互流程。(详见[service](./src/services)
6464
- **工具函数、hooks**:提供了一些方便实用的工具函数和hooks。(详见[utils](./src/utils)[hooks](./src/hooks)
65-
- **react-dev-inspector集成**:点击页面元素,IDE直接打开对应代码插件,方便开发者调试代码,提高开发效率。(详见[vite.config.ts](./vite.config.ts)
6665
- **import顺序自动美化排序**:集成了 prettier-plugin-sort-imports 插件,可以自动美化 import 顺序,提高代码的可读性和可维护性。
6766
- **其他**:提供一些方便根据环境运行、打包的命令;配置了分包策略;本地反向代理解决跨域;还有详细的`保姆级注释`等等。
6867

@@ -126,12 +125,6 @@ pnpm build:pro
126125
- 统一的 commit message 规范(Commitlint + Husky)
127126
- 自动格式化代码,保证团队代码风格一致性
128127

129-
### 🔧 强大的开发工具链
130-
131-
- react-dev-inspector 集成,点击页面元素直接跳转到源码
132-
- import 顺序自动排序,提高代码可读性
133-
- 多环境配置(dev/test/pro),满足不同部署需求
134-
135128
## 📦 关于路由缓存 keep-alive
136129

137130
> React 官方暂时没有实现 vue \<keep-alive\> 类似的功能。React 官方出于两点考虑拒绝添加这个功能,具体可以自行搜索查阅。为了达到状态保存的效果,官方推荐以下两种手动保存状态的方式:

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,19 @@
6161
"@commitlint/prompt-cli": "^20.2.0",
6262
"@eslint-react/eslint-plugin": "2.3.13",
6363
"@eslint/js": "^9.39.2",
64-
"@react-dev-inspector/vite-plugin": "^2.0.1",
6564
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
6665
"@types/node": "^25.0.2",
6766
"@types/react": "^19.2.7",
6867
"@types/react-dom": "^19.2.3",
6968
"@vitejs/plugin-react-swc": "^4.2.2",
69+
"code-inspector-plugin": "1.4.1",
7070
"eslint": "^9.39.2",
7171
"eslint-plugin-react-hooks": "^7.0.1",
7272
"eslint-plugin-react-refresh": "^0.4.25",
7373
"globals": "^16.5.0",
7474
"husky": "^9.1.7",
7575
"lint-staged": "^16.2.7",
7676
"prettier": "^3.7.4",
77-
"react-dev-inspector": "^2.0.1",
7877
"sass": "^1.96.0",
7978
"stylelint": "^16.26.1",
8079
"stylelint-config-recess-order": "^7.4.0",

pnpm-lock.yaml

Lines changed: 148 additions & 972 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as AutoScrollToTop } from './auto-scroll-to-top';
22
export { default as HighLight } from './high-light';
33
export { default as NotFount } from './not-fount';
44
export { default as Loading } from './loading';
5+
export { default as ErrorBoundary } from './error-boundary';

src/main.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Inspector } from 'react-dev-inspector';
21
import { createRoot } from 'react-dom/client';
32

43
// 公共样式
@@ -7,12 +6,7 @@ import '@/styles/scss/global.scss';
76
import App from './app.tsx';
87

98
function setupApp() {
10-
createRoot(document.getElementById('root')!).render(
11-
<>
12-
<Inspector keys={['ctrl', 'alt', 'q']} />
13-
<App />
14-
</>,
15-
);
9+
createRoot(document.getElementById('root')!).render(<App />);
1610
}
1711

1812
setupApp();

src/router/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { lazy } from 'react';
22
import { Navigate, RouteObject, createBrowserRouter } from 'react-router';
33

4-
import ErrorBoundary from '@/components/error-boundary';
4+
import { ErrorBoundary } from '@/components';
55

66
import { LazyLoad, routes } from './utils';
77

src/services/service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import axios, { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
22

3+
// import { Loading } from '@/components';
4+
35
// 创建axios实例
46
const axiosInstance: AxiosInstance = axios.create({
57
baseURL: import.meta.env.VITE_API_BASE_URL, // 请求的默认前缀 只要是发出去请求就会 默认带上这个前缀
6-
timeout: 10000, // 请求超时时间:10s
8+
timeout: 60000, // 请求超时时间:60s
79
headers: { 'Content-Type': 'application/json' }, // 设置默认请求头
810
});
911

@@ -15,9 +17,15 @@ axiosInstance.interceptors.request.use(
1517
// if (token) {
1618
// config.headers.Authorization = `Bearer ${token}`
1719
// }
20+
21+
// 全局 loading 显示
22+
// Loading.show();
23+
1824
return config;
1925
},
2026
(err: AxiosError) => {
27+
// 全局 loading 隐藏
28+
// Loading.hide();
2129
return Promise.reject(err);
2230
},
2331
);
@@ -35,11 +43,19 @@ axiosInstance.interceptors.response.use(
3543
// default:
3644
// return res.data || {};
3745
// }
46+
47+
// 全局 loading 隐藏
48+
// Loading.hide();
49+
3850
return res; // res.data
3951
},
4052
(err: AxiosError) => {
4153
// 如果接口请求报错时,也可以直接返回对象,如return { message: onErrorReason(error.message) },这样使用async/await就不需要加try/catch
4254
// onErrorReason(err.message) // 做一些全局的错误提示,可用ui库的message提示组件
55+
56+
// 全局 loading 隐藏
57+
// Loading.hide();
58+
4359
return Promise.resolve(err);
4460
},
4561
);

vite.config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { inspectorServer } from '@react-dev-inspector/vite-plugin';
21
import react from '@vitejs/plugin-react-swc';
2+
import { codeInspectorPlugin } from 'code-inspector-plugin';
33
import { resolve } from 'node:path';
44
import process from 'node:process';
55
import { ConfigEnv, UserConfig, defineConfig, loadEnv } from 'vite';
@@ -13,10 +13,15 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
1313
plugins: [
1414
react(),
1515
/**
16-
* 点击页面元素,IDE直接打开对应代码插件(本项目配置的快捷键是:ctrl+alt+q,详见main.tsx)
17-
* @see https://github.com/zthxxx/react-dev-inspector
16+
* 在页面上按住组合键时,鼠标在页面移动即会在 DOM 上出现遮罩层并显示相关信息,点击一下将自动打开 IDE 并将光标定位到元素对应的代码位置
17+
* Mac 默认组合键 Option + Shift
18+
* Windows 默认组合键 Alt + Shift
19+
* 更多用法看 https://inspector.fe-dev.cn/guide/start.html
1820
*/
19-
inspectorServer(),
21+
codeInspectorPlugin({
22+
bundler: 'vite',
23+
hideConsole: true,
24+
}),
2025
// 在浏览器中直接看到上报的类型错误(更严格的类型校验)
2126
checker({
2227
typescript: true,

0 commit comments

Comments
 (0)