vite-plugin-debugger 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 金华青鸟
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+
2
+
3
+ # vite-plugin-debugger
4
+
5
+ A vite plugin provide the debugger tools for mobile devices.
6
+
7
+ **English** | [中文](./README.zh_CN.md)
8
+
9
+ ## Install
10
+
11
+ **node version:** >=14.0.0
12
+
13
+ **vite version:** >=2.0.0
14
+
15
+
16
+ ```bash
17
+ pnpm add vite-plugin-debugger -D
18
+ # or
19
+ yarn add vite-plugin-debugger -D
20
+ # or
21
+ npm i vite-plugin-debugger -D
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### For [eruda](https://github.com/liriliri/eruda)
27
+
28
+ we use eruda with CDN by default since it's unpacked size is 2.38 MB.
29
+
30
+ ```typescript
31
+ import { fileURLToPath } from 'url'
32
+ import vDebugger from 'vite-plugin-debugger'
33
+
34
+ const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
35
+
36
+ export default defineConfig(({ command, mode }) => ({
37
+ plugins: [
38
+ vDebugger({
39
+ debug: mode !== 'production',
40
+ // cdn: 'jsdelivr', // 'jsdelivr' | 'unpkg' | 'cdnjs'
41
+ // src: 'custom CDN URL',
42
+ eruda: {
43
+ options: {
44
+ tool: ['console', 'elements'],
45
+ useShadowDom: true,
46
+ autoScale: true,
47
+ defaults: {
48
+ displaySize: 50,
49
+ transparency: 0.8,
50
+ theme: 'Dark',
51
+ },
52
+ },
53
+ plugins: [
54
+ 'fps',
55
+ 'features',
56
+ 'timing',
57
+ 'memory',
58
+ 'code',
59
+ 'benchmark',
60
+ 'dom',
61
+ 'orientation',
62
+ 'touches',
63
+ // 'geolocation',
64
+ ],
65
+ },
66
+ })
67
+ ]
68
+ })
69
+ ```
70
+
71
+
72
+
73
+ ⚠ cdnjs don't provide eruda related plugins so you can specify every plugin's CDN source like:
74
+
75
+ ```
76
+ plugins: [
77
+ {
78
+ name: 'fps',
79
+ src: 'https://cdn.jsdelivr.net/npm/eruda-fps',
80
+ },
81
+ // ...
82
+ ],
83
+ ```
84
+
85
+
86
+
87
+ For more details about eruda options, please check out [eruda API](https://github.com/liriliri/eruda/blob/master/doc/API.md).
88
+
89
+ If you prefer use eruda locally, you should install eruda and it's plugins first.
90
+
91
+ ```typescript
92
+ pnpm add eruda -D
93
+ # or
94
+ yarn add eruda -D
95
+ # or
96
+ npm i eruda -D
97
+
98
+ # And some optional plugins
99
+ pnpm[yarn|npm] add eruda-fps eruda-features eruda-timing eruda-memory eruda-code eruda-benchmark eruda-dom eruda-orientation eruda-touches eruda-geolocation -D
100
+ ```
101
+
102
+ ```typescript
103
+ import { fileURLToPath } from 'url'
104
+ import vDebugger from 'vite-plugin-debugger'
105
+
106
+ const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
107
+
108
+ export default defineConfig(({ command, mode })=>({
109
+ plugins:[
110
+ vDebugger({
111
+ debug: mode !== 'production',
112
+ local: true,
113
+ entry: resolve('src/main.ts'),// vue or src/main.tsx for react
114
+ eruda: {
115
+ options: {
116
+ tool: ['console', 'elements'],
117
+ useShadowDom: true,
118
+ autoScale: true,
119
+ defaults: {
120
+ displaySize: 50,
121
+ transparency: 0.8,
122
+ theme: 'Dark',
123
+ },
124
+ },
125
+ plugins: [
126
+ 'fps',
127
+ 'features',
128
+ 'timing',
129
+ 'memory',
130
+ 'code',
131
+ 'benchmark',
132
+ 'dom',
133
+ 'orientation',
134
+ 'touches',
135
+ // 'geolocation',
136
+ ],
137
+ })
138
+ ]
139
+ })
140
+ ```
141
+
142
+ ### For [vConsole](https://github.com/Tencent/vConsole)
143
+
144
+ we use vConsole with CDN by default since it's unpacked size is 344 kB.
145
+
146
+ ```typescript
147
+ import { fileURLToPath } from 'url'
148
+ import vDebugger from 'vite-plugin-debugger'
149
+
150
+ const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
151
+
152
+ export default defineConfig(({ command, mode })=>({
153
+ plugins:[
154
+ vDebugger({
155
+ debug: mode !== 'production',
156
+ vConsole: {
157
+ options: {
158
+ theme: 'dark',
159
+ },
160
+ },
161
+ })
162
+ ]
163
+ })
164
+ ```
165
+
166
+
167
+
168
+ For more details about vConsole options, please check out [vConsole API](https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md).
169
+
170
+ If you prefer use vConsole locally, you should install vConsole first.
171
+
172
+ ```bash
173
+ pnpm add vconsole -D
174
+ # or
175
+ yarn add vconsole -D
176
+ # or
177
+ npm i vconsole -D
178
+ ```
179
+
180
+
181
+
182
+ ```typescript
183
+ import { fileURLToPath } from 'url'
184
+ import vDebugger from 'vite-plugin-debugger'
185
+
186
+ const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
187
+
188
+ export default defineConfig(({ command, mode })=>({
189
+ plugins:[
190
+ vDebugger({
191
+ debug: mode !== 'production',
192
+ local: true,
193
+ entry: resolve('src/main.ts'),// vue or src/main.tsx for react
194
+ vConsole: {
195
+ options: {
196
+ theme: 'dark',
197
+ },
198
+ },
199
+ })
200
+ ]
201
+ })
202
+ ```
203
+
204
+
205
+
206
+
207
+ ## License
208
+
209
+ [MIT](LICENSE)
File without changes
@@ -0,0 +1,62 @@
1
+ import { Plugin } from 'vite';
2
+ import { InitOptions } from 'eruda';
3
+ import { VConsoleOptions } from 'core/options.interface';
4
+
5
+ declare type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
6
+ interface ErudaOptions extends CommonOptions {
7
+ /**
8
+ * eruda options
9
+ * see also https://github.com/liriliri/eruda/blob/master/doc/API.md
10
+ */
11
+ options?: InitOptions;
12
+ /**
13
+ * eruda plugins
14
+ * see also https://github.com/liriliri/eruda#plugins
15
+ */
16
+ plugins?: ErudaPlugin[] | {
17
+ name: ErudaPlugin;
18
+ src: string;
19
+ }[];
20
+ }
21
+
22
+ interface vConsoleOptions extends CommonOptions {
23
+ options?: VConsoleOptions;
24
+ }
25
+
26
+ declare type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
27
+
28
+ interface CommonOptions {
29
+ /**
30
+ * cdn services
31
+ */
32
+ cdn?: CDN;
33
+ /**
34
+ * custom cdn url
35
+ */
36
+ src?: string;
37
+ }
38
+ interface DebuggerOptions {
39
+ /**
40
+ * debug or not
41
+ */
42
+ debug?: boolean;
43
+ /**
44
+ * use node_modules
45
+ */
46
+ local?: boolean;
47
+ /**
48
+ * if local is true, use this to specify the path
49
+ */
50
+ entry?: string | string[];
51
+ /**
52
+ * eruda options
53
+ */
54
+ eruda?: ErudaOptions;
55
+ /**
56
+ * vConsole options
57
+ */
58
+ vConsole?: vConsoleOptions;
59
+ }
60
+ declare const _default: (options: DebuggerOptions) => Plugin;
61
+
62
+ export { CommonOptions, DebuggerOptions, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,213 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ default: () => src_default
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+
26
+ // node_modules/.pnpm/slash@4.0.0/node_modules/slash/index.js
27
+ function slash(path) {
28
+ const isExtendedLengthPath = /^\\\\\?\\/.test(path);
29
+ const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
30
+ if (isExtendedLengthPath || hasNonAscii) {
31
+ return path;
32
+ }
33
+ return path.replace(/\\/g, "/");
34
+ }
35
+
36
+ // src/helpers/index.ts
37
+ var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
38
+ var transformCDN = (pkg, cdn) => {
39
+ if (cdn === "jsdelivr") {
40
+ if (Array.isArray(pkg)) {
41
+ return `https://cdn.jsdelivr.net/combine/${pkg.map((p) => `npm/${p}`).join(",")}`;
42
+ }
43
+ return `https://cdn.jsdelivr.net/npm/${pkg}`;
44
+ }
45
+ if (cdn === "unpkg") {
46
+ return `https://unpkg.com/${pkg}`;
47
+ }
48
+ if (cdn === "cdnjs") {
49
+ if (!Array.isArray(pkg)) {
50
+ if (pkg === "eruda") {
51
+ return "https://cdnjs.cloudflare.com/ajax/libs/eruda/2.4.1/eruda.min.js";
52
+ }
53
+ throw new Error(`[vite-plugin-debugger]: ${cdn} only support eruda without its plugins.`);
54
+ }
55
+ return `https://cdnjs.cloudflare.com/ajax/libs/${pkg}`;
56
+ }
57
+ return "";
58
+ };
59
+
60
+ // src/plugins/eruda.ts
61
+ var transformErudaOptions = (html, opts) => {
62
+ const { debug } = opts;
63
+ const { options, plugins, cdn = "jsdelivr", src } = opts.eruda;
64
+ const tags = [];
65
+ tags.push({
66
+ tag: "script",
67
+ attrs: {
68
+ src: src || transformCDN("eruda", cdn)
69
+ },
70
+ injectTo: "head"
71
+ });
72
+ let erudaScript = `eruda.init(${JSON.stringify(options)});
73
+ `;
74
+ if (plugins.length > 0) {
75
+ if (cdn === "jsdelivr") {
76
+ tags.push({
77
+ tag: "script",
78
+ attrs: {
79
+ src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`))
80
+ },
81
+ injectTo: "head"
82
+ });
83
+ } else {
84
+ plugins.forEach((plugin) => {
85
+ tags.push({
86
+ tag: "script",
87
+ attrs: {
88
+ src: typeof plugin === "string" ? transformCDN(`eruda-${plugin}`, cdn) : plugin.src
89
+ },
90
+ injectTo: "head"
91
+ });
92
+ });
93
+ }
94
+ plugins.forEach((plugin) => {
95
+ erudaScript += `eruda.add(eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)});
96
+ `;
97
+ });
98
+ }
99
+ tags.push({
100
+ tag: "script",
101
+ children: erudaScript,
102
+ injectTo: "head"
103
+ });
104
+ if (debug === true) {
105
+ return {
106
+ html,
107
+ tags
108
+ };
109
+ }
110
+ if (debug === false) {
111
+ return html;
112
+ }
113
+ if (process.env.NODE_ENV !== "production") {
114
+ return {
115
+ html,
116
+ tags
117
+ };
118
+ }
119
+ };
120
+ var transformErudaImport = (code, opts) => {
121
+ const { debug } = opts;
122
+ const { options = {}, plugins } = opts.eruda;
123
+ let importCode = "import eruda from 'eruda';";
124
+ let erudaScript = `eruda.init(${JSON.stringify(options)});`;
125
+ if (plugins && plugins.length > 0) {
126
+ plugins.forEach((plugin) => {
127
+ importCode += `import eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)} from 'eruda-${typeof plugin === "string" ? plugin : plugin.name}';`;
128
+ erudaScript += `eruda.add(eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)});`;
129
+ });
130
+ }
131
+ return {
132
+ code: debug ? `/* eslint-disable */;${importCode}${erudaScript}/* eslint-enable */${code}` : code,
133
+ map: null
134
+ };
135
+ };
136
+
137
+ // src/plugins/vConsole.ts
138
+ var transformVConsoleOptions = (html, opts) => {
139
+ const { debug } = opts;
140
+ const { options, cdn = "jsdelivr", src } = opts.vConsole;
141
+ const tags = [];
142
+ tags.push({
143
+ tag: "script",
144
+ attrs: {
145
+ src: src || transformCDN("vconsole", cdn)
146
+ },
147
+ injectTo: "head"
148
+ });
149
+ tags.push({
150
+ tag: "script",
151
+ children: `var vConsole = new VConsole(${JSON.stringify(options)});`,
152
+ injectTo: "head"
153
+ });
154
+ if (debug === true) {
155
+ return {
156
+ html,
157
+ tags
158
+ };
159
+ }
160
+ if (debug === false) {
161
+ return html;
162
+ }
163
+ if (process.env.NODE_ENV !== "production") {
164
+ return {
165
+ html,
166
+ tags
167
+ };
168
+ }
169
+ };
170
+ var transformVConsoleImport = (code, opts) => {
171
+ const { debug } = opts;
172
+ const { options = {} } = opts.vConsole;
173
+ return {
174
+ code: debug ? `/* eslint-disable */;import VConsole from 'vconsole';new VConsole(${JSON.stringify(options)});/* eslint-enable */${code}` : code,
175
+ map: null
176
+ };
177
+ };
178
+
179
+ // src/index.ts
180
+ var src_default = (options) => {
181
+ const { eruda, vConsole, local, entry } = options;
182
+ const entryPath = (Array.isArray(entry) ? entry : [entry]).map((path) => slash(path));
183
+ if (eruda && vConsole) {
184
+ throw new Error("[vite-plugin-debugger]: You'd better use only one debugger tool at a time.");
185
+ }
186
+ return {
187
+ name: "vite-plugin-debugger",
188
+ transformIndexHtml(html) {
189
+ if (!local) {
190
+ if (eruda) {
191
+ return transformErudaOptions(html, options);
192
+ }
193
+ if (vConsole) {
194
+ return transformVConsoleOptions(html, options);
195
+ }
196
+ }
197
+ return html;
198
+ },
199
+ transform(code, id) {
200
+ if (local) {
201
+ if (eruda && entryPath.includes(id)) {
202
+ return transformErudaImport(code, options);
203
+ }
204
+ if (vConsole && entryPath.includes(id)) {
205
+ return transformVConsoleImport(code, options);
206
+ }
207
+ }
208
+ return { code, map: null };
209
+ }
210
+ };
211
+ };
212
+ // Annotate the CommonJS export names for ESM import in node:
213
+ 0 && (module.exports = {});
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "vite-plugin-debugger",
3
+ "version": "0.0.1",
4
+ "description": "A vite plugin provide the debugger tools for mobile devices.",
5
+ "author": "jade-gjz",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "vite",
9
+ "debugger",
10
+ "plugin",
11
+ "eruda",
12
+ "vConsole",
13
+ "mobile"
14
+ ],
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "peerDependencies": {
21
+ "eruda": "^2.0.0",
22
+ "vconsole": "^3.0.0",
23
+ "vite": "^2.0.0"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "eruda": {
27
+ "optional": true
28
+ },
29
+ "vconsole": {
30
+ "optional": true
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@jhqn/eslint-config-ts": "^0.0.30",
35
+ "bumpp": "^8.2.1",
36
+ "conventional-changelog-cli": "^2.2.2",
37
+ "eruda": "https://github.com/liriliri/eruda.git",
38
+ "eslint": "^8.19.0",
39
+ "slash": "^4.0.0",
40
+ "tsup": "^6.1.3",
41
+ "typescript": "^4.7.4",
42
+ "vconsole": "^3.14.6",
43
+ "vite": "^2.9.13"
44
+ },
45
+ "scripts": {
46
+ "dev": "tsup src/index.ts --dts --watch",
47
+ "build": "tsup src/index.ts --dts",
48
+ "prepublish": "pnpm build",
49
+ "lint": "eslint . --fix",
50
+ "release": "bumpp package.json --commit --push --tag && pnpm publish --access public"
51
+ }
52
+ }