vite-plugin-debugger 0.2.0 → 0.3.1
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 +177 -0
- package/README.zh_CN.md +176 -0
- package/dist/chunk-EPGFZDIC.js +75 -0
- package/dist/chunk-UKUUEXI7.js +7234 -0
- package/dist/chunk-X6FL4XDU.js +75 -0
- package/dist/eruda.d.ts +22 -0
- package/dist/eruda.js +9 -0
- package/dist/index.d-D0Oa6UqJ.d.ts +48 -0
- package/dist/index.d.ts +6 -89
- package/dist/index.js +10 -247
- package/dist/precompiled/eruda/dynamic-import.js +1 -0
- package/dist/precompiled/eruda/prepend-script.js +1 -0
- package/dist/precompiled/show-or-not.js +1 -0
- package/dist/precompiled/vconsole/dynamic-import.js +1 -0
- package/dist/precompiled/vconsole/prepend-script.js +1 -0
- package/dist/vconsole.d.ts +22 -0
- package/dist/vconsole.js +9 -0
- package/package.json +28 -5
package/README.md
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
# vite-plugin-debugger
|
2
|
+
|
3
|
+
A vite plugin provide the debugger tools for mobile devices.
|
4
|
+
|
5
|
+
<a href="https://npmjs.com/package/vite-plugin-debugger" target="\_parent">
|
6
|
+
<img alt="" src="https://img.shields.io/npm/dm/vite-plugin-debugger.svg" />
|
7
|
+
</a><a href="https://www.npmjs.com/package/vite-plugin-debugger">
|
8
|
+
<img src="https://badgen.net/npm/v/vite-plugin-debugger" alt="">
|
9
|
+
</a><a href="https://github.com/jaderd-jh/vite-plugin-debugger" target="\_parent">
|
10
|
+
<img alt="" src="https://img.shields.io/github/stars/jaderd-jh/vite-plugin-debugger.svg?style=social&label=Star" />
|
11
|
+
</a>
|
12
|
+
|
13
|
+
**English** | [中文](README.zh_CN.md)
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
**node version:** >=20.0.0
|
18
|
+
|
19
|
+
**vite version:** >=6.0.0
|
20
|
+
|
21
|
+
```bash
|
22
|
+
pnpm add vite-plugin-debugger -D
|
23
|
+
# or
|
24
|
+
yarn add vite-plugin-debugger -D
|
25
|
+
# or
|
26
|
+
npm i vite-plugin-debugger -D
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### For [eruda](https://github.com/liriliri/eruda)
|
32
|
+
|
33
|
+
we use eruda with CDN by default since it's unpacked size is 2.38 MB.
|
34
|
+
|
35
|
+
```typescript
|
36
|
+
import vDebugger from 'vite-plugin-debugger/eruda'
|
37
|
+
|
38
|
+
export default defineConfig(({ command, mode }) => ({
|
39
|
+
plugins: [
|
40
|
+
vDebugger({
|
41
|
+
debug: mode !== 'production',
|
42
|
+
eruda: {
|
43
|
+
// cdn: 'jsdelivr', // 'jsdelivr' | 'unpkg' | 'cdnjs' | 'staticfile'
|
44
|
+
// src: 'custom CDN URL',
|
45
|
+
options: {
|
46
|
+
tool: ['console', 'elements'],
|
47
|
+
useShadowDom: true,
|
48
|
+
autoScale: true,
|
49
|
+
defaults: {
|
50
|
+
displaySize: 50,
|
51
|
+
transparency: 0.8,
|
52
|
+
theme: 'Dark',
|
53
|
+
},
|
54
|
+
},
|
55
|
+
},
|
56
|
+
})
|
57
|
+
]
|
58
|
+
}))
|
59
|
+
```
|
60
|
+
|
61
|
+
Use active tools to enable eruda forcibly, you can specify activation mode and parameter name like:
|
62
|
+
```typescript
|
63
|
+
const config = {
|
64
|
+
active: {
|
65
|
+
override: true, // true if you want to override debug option
|
66
|
+
mode: 'url',
|
67
|
+
param: 'debugwhatever',
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
For more details about eruda options, please check
|
73
|
+
out [eruda API](https://github.com/liriliri/eruda/blob/master/doc/API.md).
|
74
|
+
|
75
|
+
If you prefer use eruda locally, you should install eruda and it's plugins first.
|
76
|
+
|
77
|
+
```bash
|
78
|
+
pnpm add eruda -D
|
79
|
+
# or
|
80
|
+
yarn add eruda -D
|
81
|
+
# or
|
82
|
+
npm i eruda -D
|
83
|
+
|
84
|
+
```
|
85
|
+
|
86
|
+
```typescript
|
87
|
+
import { fileURLToPath } from 'node:url'
|
88
|
+
import vDebugger from 'vite-plugin-debugger/eruda'
|
89
|
+
|
90
|
+
const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
|
91
|
+
|
92
|
+
export default defineConfig(({ command, mode }) => ({
|
93
|
+
plugins: [
|
94
|
+
vDebugger({
|
95
|
+
debug: mode !== 'production',
|
96
|
+
local: true,
|
97
|
+
entry: resolve('src/main.ts'), // vue or src/main.tsx for react
|
98
|
+
eruda: {
|
99
|
+
options: {
|
100
|
+
tool: ['console', 'elements'],
|
101
|
+
useShadowDom: true,
|
102
|
+
autoScale: true,
|
103
|
+
defaults: {
|
104
|
+
displaySize: 50,
|
105
|
+
transparency: 0.8,
|
106
|
+
theme: 'Dark',
|
107
|
+
},
|
108
|
+
},
|
109
|
+
}
|
110
|
+
})
|
111
|
+
]
|
112
|
+
}))
|
113
|
+
```
|
114
|
+
|
115
|
+
### For [vConsole](https://github.com/Tencent/vConsole)
|
116
|
+
|
117
|
+
we use vConsole with CDN by default since it's unpacked size is 344 kB.
|
118
|
+
|
119
|
+
```typescript
|
120
|
+
import vDebugger from 'vite-plugin-debugger/vconsole'
|
121
|
+
|
122
|
+
export default defineConfig(({ command, mode }) => ({
|
123
|
+
plugins: [
|
124
|
+
vDebugger({
|
125
|
+
debug: mode !== 'production',
|
126
|
+
vConsole: {
|
127
|
+
options: {
|
128
|
+
theme: 'dark',
|
129
|
+
},
|
130
|
+
},
|
131
|
+
})
|
132
|
+
]
|
133
|
+
}))
|
134
|
+
```
|
135
|
+
|
136
|
+
Use active tools to enable vConsole dynamically, you can specify activation mode and parameter name like:
|
137
|
+
|
138
|
+
active: { mode: 'url', param: 'debugwhatever' },
|
139
|
+
|
140
|
+
For more details about vConsole options, please check
|
141
|
+
out [vConsole API](https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md).
|
142
|
+
|
143
|
+
If you prefer use vConsole locally, you should install vConsole first.
|
144
|
+
|
145
|
+
```bash
|
146
|
+
pnpm add vconsole -D
|
147
|
+
# or
|
148
|
+
yarn add vconsole -D
|
149
|
+
# or
|
150
|
+
npm i vconsole -D
|
151
|
+
```
|
152
|
+
|
153
|
+
```typescript
|
154
|
+
import { fileURLToPath } from 'node:url'
|
155
|
+
import vDebugger from 'vite-plugin-debugger/vconsole'
|
156
|
+
|
157
|
+
const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
|
158
|
+
|
159
|
+
export default defineConfig(({ command, mode }) => ({
|
160
|
+
plugins: [
|
161
|
+
vDebugger({
|
162
|
+
debug: mode !== 'production',
|
163
|
+
local: true,
|
164
|
+
entry: resolve('src/main.ts'), // vue or src/main.tsx for react
|
165
|
+
vConsole: {
|
166
|
+
options: {
|
167
|
+
theme: 'dark',
|
168
|
+
},
|
169
|
+
},
|
170
|
+
})
|
171
|
+
]
|
172
|
+
}))
|
173
|
+
```
|
174
|
+
|
175
|
+
## License
|
176
|
+
|
177
|
+
[MIT](../../LICENSE)
|
package/README.zh_CN.md
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
# vite-plugin-debugger
|
2
|
+
|
3
|
+
一个提供移动端debug工具的vite插件
|
4
|
+
|
5
|
+
<a href="https://npmjs.com/package/vite-plugin-debugger" target="\_parent">
|
6
|
+
<img alt="" src="https://img.shields.io/npm/dm/vite-plugin-debugger.svg" />
|
7
|
+
</a><a href="https://www.npmjs.com/package/vite-plugin-debugger">
|
8
|
+
<img src="https://badgen.net/npm/v/vite-plugin-debugger" alt="">
|
9
|
+
</a><a href="https://github.com/jaderd-jh/vite-plugin-debugger" target="\_parent">
|
10
|
+
<img alt="" src="https://img.shields.io/github/stars/jaderd-jh/vite-plugin-debugger.svg?style=social&label=Star" />
|
11
|
+
</a>
|
12
|
+
|
13
|
+
**English** | [中文](README.zh_CN.md)
|
14
|
+
|
15
|
+
## 安装
|
16
|
+
|
17
|
+
**node 版本:** >=20.0.0
|
18
|
+
|
19
|
+
**vite 版本:** >=6.0.0
|
20
|
+
|
21
|
+
```bash
|
22
|
+
pnpm add vite-plugin-debugger -D
|
23
|
+
# or
|
24
|
+
yarn add vite-plugin-debugger -D
|
25
|
+
# or
|
26
|
+
npm i vite-plugin-debugger -D
|
27
|
+
```
|
28
|
+
|
29
|
+
## 使用
|
30
|
+
|
31
|
+
### For [eruda](https://github.com/liriliri/eruda)
|
32
|
+
|
33
|
+
由于eruda的未打包大小有2.38MB,所以我们推荐默认使用CDN方式引入
|
34
|
+
|
35
|
+
```typescript
|
36
|
+
import vDebugger from 'vite-plugin-debugger/eruda'
|
37
|
+
|
38
|
+
export default defineConfig(({ command, mode }) => ({
|
39
|
+
plugins: [
|
40
|
+
vDebugger({
|
41
|
+
debug: mode !== 'production',
|
42
|
+
eruda: {
|
43
|
+
// cdn: 'jsdelivr', // 'jsdelivr' | 'unpkg' | 'cdnjs'
|
44
|
+
// src: 'custom CDN URL',
|
45
|
+
options: {
|
46
|
+
tool: ['console', 'elements'],
|
47
|
+
useShadowDom: true,
|
48
|
+
autoScale: true,
|
49
|
+
defaults: {
|
50
|
+
displaySize: 50,
|
51
|
+
transparency: 0.8,
|
52
|
+
theme: 'Dark',
|
53
|
+
},
|
54
|
+
},
|
55
|
+
},
|
56
|
+
})
|
57
|
+
]
|
58
|
+
}))
|
59
|
+
```
|
60
|
+
|
61
|
+
使用active工具强制开启eruda,您可以像这样指定激活方法和参数名:
|
62
|
+
|
63
|
+
```typescript
|
64
|
+
const config = {
|
65
|
+
active: {
|
66
|
+
override: true, // 设置为true以覆盖debug选项
|
67
|
+
mode: 'url',
|
68
|
+
param: 'debugwhatever',
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
想了解更多有关eruda配置,请移至 [eruda API](https://github.com/liriliri/eruda/blob/master/doc/API.md).
|
74
|
+
|
75
|
+
如果您偏好于在本地使用eruda,您应该先安装reuda及其插件。
|
76
|
+
|
77
|
+
```bash
|
78
|
+
pnpm add eruda -D
|
79
|
+
# or
|
80
|
+
yarn add eruda -D
|
81
|
+
# or
|
82
|
+
npm i eruda -D
|
83
|
+
|
84
|
+
```
|
85
|
+
|
86
|
+
```typescript
|
87
|
+
import { fileURLToPath } from 'node:url'
|
88
|
+
import vDebugger from 'vite-plugin-debugger/eruda'
|
89
|
+
|
90
|
+
const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
|
91
|
+
|
92
|
+
export default defineConfig(({ command, mode }) => ({
|
93
|
+
plugins: [
|
94
|
+
vDebugger({
|
95
|
+
debug: mode !== 'production',
|
96
|
+
local: true,
|
97
|
+
entry: resolve('src/main.ts'), // vue or src/main.tsx for react
|
98
|
+
eruda: {
|
99
|
+
options: {
|
100
|
+
tool: ['console', 'elements'],
|
101
|
+
useShadowDom: true,
|
102
|
+
autoScale: true,
|
103
|
+
defaults: {
|
104
|
+
displaySize: 50,
|
105
|
+
transparency: 0.8,
|
106
|
+
theme: 'Dark',
|
107
|
+
},
|
108
|
+
},
|
109
|
+
}
|
110
|
+
})
|
111
|
+
]
|
112
|
+
}))
|
113
|
+
```
|
114
|
+
|
115
|
+
### For [vConsole](https://github.com/Tencent/vConsole)
|
116
|
+
|
117
|
+
由于vConsole的未打包大小有344kb,所以我们推荐默认使用CDN方式引入
|
118
|
+
|
119
|
+
```typescript
|
120
|
+
import vDebugger from 'vite-plugin-debugger/vconsole'
|
121
|
+
|
122
|
+
export default defineConfig(({ command, mode }) => ({
|
123
|
+
plugins: [
|
124
|
+
vDebugger({
|
125
|
+
debug: mode !== 'production',
|
126
|
+
vConsole: {
|
127
|
+
options: {
|
128
|
+
theme: 'dark',
|
129
|
+
},
|
130
|
+
},
|
131
|
+
})
|
132
|
+
]
|
133
|
+
}))
|
134
|
+
```
|
135
|
+
|
136
|
+
使用active配置动态开启vConsole,您可以像这样指定激活方法和参数名:
|
137
|
+
|
138
|
+
active: { mode: 'url', param: 'debugwhatever' },
|
139
|
+
|
140
|
+
想了解更多有关vConsole配置,请移至 [vConsole API](https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md).
|
141
|
+
|
142
|
+
如果您偏好于在本地使用vConsole,您应该先安装vConsole及其插件。
|
143
|
+
|
144
|
+
```bash
|
145
|
+
pnpm add vconsole -D
|
146
|
+
# or
|
147
|
+
yarn add vconsole -D
|
148
|
+
# or
|
149
|
+
npm i vconsole -D
|
150
|
+
```
|
151
|
+
|
152
|
+
```typescript
|
153
|
+
import { fileURLToPath } from 'node:url'
|
154
|
+
import vDebugger from 'vite-plugin-debugger/vconsole'
|
155
|
+
|
156
|
+
const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
|
157
|
+
|
158
|
+
export default defineConfig(({ command, mode }) => ({
|
159
|
+
plugins: [
|
160
|
+
vDebugger({
|
161
|
+
debug: mode !== 'production',
|
162
|
+
local: true,
|
163
|
+
entry: resolve('src/main.ts'), // vue or src/main.tsx for react
|
164
|
+
vConsole: {
|
165
|
+
options: {
|
166
|
+
theme: 'dark',
|
167
|
+
},
|
168
|
+
},
|
169
|
+
})
|
170
|
+
]
|
171
|
+
}))
|
172
|
+
```
|
173
|
+
|
174
|
+
## License
|
175
|
+
|
176
|
+
[MIT](../../LICENSE)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import {
|
2
|
+
isPackageExists,
|
3
|
+
readFileContent,
|
4
|
+
transformCDN
|
5
|
+
} from "./chunk-UKUUEXI7.js";
|
6
|
+
|
7
|
+
// src/plugins/vconsole.ts
|
8
|
+
import { normalizePath } from "vite";
|
9
|
+
var transformVConsoleOptions = async (html, opts) => {
|
10
|
+
const { debug, active } = opts;
|
11
|
+
const { options, cdn = "jsdelivr", src } = opts.config;
|
12
|
+
const tags = [];
|
13
|
+
let injectCodes = ``;
|
14
|
+
injectCodes += "\n(function(debug,active,options,cdn){\n";
|
15
|
+
injectCodes += readFileContent("./precompiled/show-or-not.js");
|
16
|
+
injectCodes += readFileContent("./precompiled/vconsole/prepend-script.js");
|
17
|
+
injectCodes += `
|
18
|
+
})(${debug},${JSON.stringify(active)},${JSON.stringify(options)},${JSON.stringify(src || await transformCDN("vConsole", cdn))});
|
19
|
+
`;
|
20
|
+
tags.push({
|
21
|
+
tag: "script",
|
22
|
+
injectTo: "head",
|
23
|
+
children: injectCodes
|
24
|
+
});
|
25
|
+
if (debug !== void 0) {
|
26
|
+
return {
|
27
|
+
html,
|
28
|
+
tags
|
29
|
+
};
|
30
|
+
}
|
31
|
+
};
|
32
|
+
var transformVConsoleImport = (code, opts) => {
|
33
|
+
const { debug, active } = opts;
|
34
|
+
const { options = {} } = opts.config;
|
35
|
+
let injectCodes = ``;
|
36
|
+
injectCodes += "\n/* eslint-disable */\n";
|
37
|
+
injectCodes += "\n(function(debug,active,options){\n";
|
38
|
+
injectCodes += readFileContent("./precompiled/show-or-not.js");
|
39
|
+
injectCodes += readFileContent("./precompiled/vconsole/dynamic-import.js");
|
40
|
+
injectCodes += `
|
41
|
+
})(${debug},${JSON.stringify(active)},${JSON.stringify(options)});
|
42
|
+
`;
|
43
|
+
injectCodes += "\n/* eslint-enable */\n";
|
44
|
+
return {
|
45
|
+
code: `${injectCodes}${code}`,
|
46
|
+
map: null
|
47
|
+
};
|
48
|
+
};
|
49
|
+
function vDebugger(options) {
|
50
|
+
const { local = isPackageExists("vconsole"), entry } = options;
|
51
|
+
const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => normalizePath(path)) : [];
|
52
|
+
if (local) {
|
53
|
+
return {
|
54
|
+
name: "vite:mobile-devtools:vconsole",
|
55
|
+
transform(code, id) {
|
56
|
+
if (entryPath.includes(id)) {
|
57
|
+
return transformVConsoleImport(code, options);
|
58
|
+
}
|
59
|
+
return { code, map: null };
|
60
|
+
}
|
61
|
+
};
|
62
|
+
}
|
63
|
+
return {
|
64
|
+
name: "vite:mobile-devtools:vconsole",
|
65
|
+
transformIndexHtml: async (html) => {
|
66
|
+
return await transformVConsoleOptions(html, options);
|
67
|
+
}
|
68
|
+
};
|
69
|
+
}
|
70
|
+
var vconsole_default = vDebugger;
|
71
|
+
|
72
|
+
export {
|
73
|
+
vDebugger,
|
74
|
+
vconsole_default
|
75
|
+
};
|