@linhey/react-debug-inspector 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -7
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +41 -0
- package/dist/index.mjs +30 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -48,23 +48,33 @@ npm install @linhey/react-debug-inspector --save-dev
|
|
|
48
48
|
|
|
49
49
|
### 1. 配置 Vite (vite.config.ts)
|
|
50
50
|
|
|
51
|
+
推荐在 Vite 8+ 使用官方导出的插件工厂,确保 `data-debug` 注入稳定:
|
|
52
|
+
|
|
51
53
|
```typescript
|
|
52
54
|
import { defineConfig } from 'vite';
|
|
53
55
|
import react from '@vitejs/plugin-react';
|
|
54
|
-
import
|
|
56
|
+
import { createViteDebugInspectorPlugin } from '@linhey/react-debug-inspector';
|
|
55
57
|
|
|
56
58
|
export default defineConfig({
|
|
57
59
|
plugins: [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// 仅在开发环境下启用注入
|
|
61
|
-
plugins: process.env.NODE_ENV === 'development' ? [debugInspector] : []
|
|
62
|
-
}
|
|
63
|
-
}),
|
|
60
|
+
createViteDebugInspectorPlugin(),
|
|
61
|
+
react(),
|
|
64
62
|
],
|
|
65
63
|
});
|
|
66
64
|
```
|
|
67
65
|
|
|
66
|
+
如果你仍在旧链路中使用 Babel 直接注入,也可以保留:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import debugInspector from '@linhey/react-debug-inspector';
|
|
70
|
+
|
|
71
|
+
react({
|
|
72
|
+
babel: {
|
|
73
|
+
plugins: [debugInspector],
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
68
78
|
### 2. 初始化交互界面 (main.tsx)
|
|
69
79
|
|
|
70
80
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -9,4 +9,16 @@ declare function babelPluginDebugLabel(): {
|
|
|
9
9
|
*/
|
|
10
10
|
declare function initInspector(): void;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type TransformResult = {
|
|
13
|
+
code: string;
|
|
14
|
+
map: object | null;
|
|
15
|
+
};
|
|
16
|
+
type ViteCompatiblePlugin = {
|
|
17
|
+
name: string;
|
|
18
|
+
apply: 'serve';
|
|
19
|
+
enforce: 'pre';
|
|
20
|
+
transform: (code: string, id: string) => Promise<TransformResult | null>;
|
|
21
|
+
};
|
|
22
|
+
declare function createViteDebugInspectorPlugin(): ViteCompatiblePlugin;
|
|
23
|
+
|
|
24
|
+
export { createViteDebugInspectorPlugin, babelPluginDebugLabel as default, initInspector };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,4 +9,16 @@ declare function babelPluginDebugLabel(): {
|
|
|
9
9
|
*/
|
|
10
10
|
declare function initInspector(): void;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type TransformResult = {
|
|
13
|
+
code: string;
|
|
14
|
+
map: object | null;
|
|
15
|
+
};
|
|
16
|
+
type ViteCompatiblePlugin = {
|
|
17
|
+
name: string;
|
|
18
|
+
apply: 'serve';
|
|
19
|
+
enforce: 'pre';
|
|
20
|
+
transform: (code: string, id: string) => Promise<TransformResult | null>;
|
|
21
|
+
};
|
|
22
|
+
declare function createViteDebugInspectorPlugin(): ViteCompatiblePlugin;
|
|
23
|
+
|
|
24
|
+
export { createViteDebugInspectorPlugin, babelPluginDebugLabel as default, initInspector };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,11 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
33
|
+
createViteDebugInspectorPlugin: () => createViteDebugInspectorPlugin,
|
|
23
34
|
default: () => index_default,
|
|
24
35
|
initInspector: () => initInspector
|
|
25
36
|
});
|
|
@@ -726,9 +737,39 @@ function initInspector() {
|
|
|
726
737
|
};
|
|
727
738
|
}
|
|
728
739
|
|
|
740
|
+
// src/vite-plugin.ts
|
|
741
|
+
function createViteDebugInspectorPlugin() {
|
|
742
|
+
return {
|
|
743
|
+
name: "react-debug-inspector-transform",
|
|
744
|
+
apply: "serve",
|
|
745
|
+
enforce: "pre",
|
|
746
|
+
async transform(code, id) {
|
|
747
|
+
if (id.includes("node_modules")) return null;
|
|
748
|
+
if (!/\.[jt]sx($|\?)/.test(id)) return null;
|
|
749
|
+
const { transformAsync } = await import("@babel/core");
|
|
750
|
+
const result = await transformAsync(code, {
|
|
751
|
+
filename: id,
|
|
752
|
+
babelrc: false,
|
|
753
|
+
configFile: false,
|
|
754
|
+
plugins: [babelPluginDebugLabel()],
|
|
755
|
+
parserOpts: {
|
|
756
|
+
plugins: ["jsx", "typescript"]
|
|
757
|
+
},
|
|
758
|
+
sourceMaps: true
|
|
759
|
+
});
|
|
760
|
+
if (!result?.code) return null;
|
|
761
|
+
return {
|
|
762
|
+
code: result.code,
|
|
763
|
+
map: result.map ?? null
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
729
769
|
// src/index.ts
|
|
730
770
|
var index_default = babelPluginDebugLabel;
|
|
731
771
|
// Annotate the CommonJS export names for ESM import in node:
|
|
732
772
|
0 && (module.exports = {
|
|
773
|
+
createViteDebugInspectorPlugin,
|
|
733
774
|
initInspector
|
|
734
775
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -699,9 +699,39 @@ function initInspector() {
|
|
|
699
699
|
};
|
|
700
700
|
}
|
|
701
701
|
|
|
702
|
+
// src/vite-plugin.ts
|
|
703
|
+
function createViteDebugInspectorPlugin() {
|
|
704
|
+
return {
|
|
705
|
+
name: "react-debug-inspector-transform",
|
|
706
|
+
apply: "serve",
|
|
707
|
+
enforce: "pre",
|
|
708
|
+
async transform(code, id) {
|
|
709
|
+
if (id.includes("node_modules")) return null;
|
|
710
|
+
if (!/\.[jt]sx($|\?)/.test(id)) return null;
|
|
711
|
+
const { transformAsync } = await import("@babel/core");
|
|
712
|
+
const result = await transformAsync(code, {
|
|
713
|
+
filename: id,
|
|
714
|
+
babelrc: false,
|
|
715
|
+
configFile: false,
|
|
716
|
+
plugins: [babelPluginDebugLabel()],
|
|
717
|
+
parserOpts: {
|
|
718
|
+
plugins: ["jsx", "typescript"]
|
|
719
|
+
},
|
|
720
|
+
sourceMaps: true
|
|
721
|
+
});
|
|
722
|
+
if (!result?.code) return null;
|
|
723
|
+
return {
|
|
724
|
+
code: result.code,
|
|
725
|
+
map: result.map ?? null
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
702
731
|
// src/index.ts
|
|
703
732
|
var index_default = babelPluginDebugLabel;
|
|
704
733
|
export {
|
|
734
|
+
createViteDebugInspectorPlugin,
|
|
705
735
|
index_default as default,
|
|
706
736
|
initInspector
|
|
707
737
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linhey/react-debug-inspector",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "A developer tool to inspect React components in browser and jump to source code.",
|
|
5
5
|
"author": "linhey",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
19
19
|
"dev:test-app": "vite --config vite.config.test.ts",
|
|
20
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --external @babel/core",
|
|
21
21
|
"test": "vitest run",
|
|
22
22
|
"test:e2e": "playwright test",
|
|
23
23
|
"test:e2e:ui": "playwright test --ui",
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"test:all": "npm run test && npm run test:e2e",
|
|
26
26
|
"prepublishOnly": "npm run build"
|
|
27
27
|
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@babel/core": "^7.24.0"
|
|
30
|
+
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.24.0",
|
|
30
32
|
"@playwright/test": "^1.58.2",
|
|
31
33
|
"@types/node": "^25.3.5",
|
|
32
34
|
"@types/react": "^19.2.14",
|