vite-plugin-debugger 0.0.5 → 0.0.7

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/dist/index.d.ts CHANGED
@@ -2,15 +2,19 @@ import { Plugin } from 'vite';
2
2
  import { InitOptions } from 'eruda';
3
3
  import { VConsoleOptions } from 'core/options.interface';
4
4
 
5
+ declare type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
6
+
5
7
  declare type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
6
- interface ErudaOptions extends CommonOptions {
8
+ interface ErudaConfig extends CommonConfig {
7
9
  /**
8
10
  * eruda options
11
+ *
9
12
  * see also https://github.com/liriliri/eruda/blob/master/doc/API.md
10
13
  */
11
14
  options?: InitOptions;
12
15
  /**
13
16
  * eruda plugins
17
+ *
14
18
  * see also https://github.com/liriliri/eruda#plugins
15
19
  */
16
20
  plugins?: ErudaPlugin[] | {
@@ -19,44 +23,63 @@ interface ErudaOptions extends CommonOptions {
19
23
  }[];
20
24
  }
21
25
 
22
- interface vConsoleOptions extends CommonOptions {
26
+ interface VConsoleConfig extends CommonConfig {
27
+ /**
28
+ * vConsole options
29
+ *
30
+ * see also https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md#vconsoleoption
31
+ */
23
32
  options?: VConsoleOptions;
24
33
  }
25
34
 
26
- declare type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
35
+ interface CommonConfig {
36
+ /**
37
+ * cdn services
38
+ */
39
+ cdn?: CDN
40
+ /**
41
+ * custom cdn url
42
+ */
43
+ src?: string
44
+ }
27
45
 
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;
46
+ interface ActiveConfig {
47
+ /**
48
+ * use url or storage
49
+ */
50
+ mode: 'url' | 'storage'
51
+ /**
52
+ * parameter name
53
+ */
54
+ param?: string
55
+ }
56
+ interface DebuggerOptions {
57
+ /**
58
+ * debug or not
59
+ */
60
+ debug?: boolean
61
+ /**
62
+ * active debugger
63
+ */
64
+ active?: ActiveConfig
65
+ /**
66
+ * use node_modules
67
+ */
68
+ local?: boolean
69
+ /**
70
+ * if local is true, use this to specify the path
71
+ */
72
+ entry?: string | string[]
73
+ /**
74
+ * eruda config
75
+ */
76
+ eruda?: ErudaConfig
77
+ /**
78
+ * vConsole config
79
+ */
80
+ vConsole?: VConsoleConfig
81
+ }
82
+
83
+ declare const vDebugger: (options: DebuggerOptions) => Plugin;
61
84
 
62
- export { CommonOptions, DebuggerOptions, _default as default };
85
+ export { vDebugger as default, vDebugger };
package/dist/index.js CHANGED
@@ -19,19 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.ts
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
- default: () => src_default
22
+ default: () => src_default,
23
+ vDebugger: () => vDebugger
23
24
  });
24
25
  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
- }
26
+ var import_vite = require("vite");
35
27
 
36
28
  // src/helpers/index.ts
37
29
  var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
@@ -48,7 +40,7 @@ var transformCDN = (pkg, cdn) => {
48
40
  if (cdn === "cdnjs") {
49
41
  if (!Array.isArray(pkg)) {
50
42
  if (pkg === "eruda") {
51
- return "https://cdnjs.cloudflare.com/ajax/libs/eruda/2.4.1/eruda.min.js";
43
+ return "https://cdnjs.cloudflare.com/ajax/libs/eruda/2.5.0/eruda.min.js";
52
44
  }
53
45
  throw new Error(`[vite-plugin-debugger]: ${cdn} only support eruda without its plugins.`);
54
46
  }
@@ -56,10 +48,26 @@ var transformCDN = (pkg, cdn) => {
56
48
  }
57
49
  return "";
58
50
  };
51
+ var debugInit = (debug, active) => {
52
+ return `
53
+ let showDebug=${debug};
54
+ let storageStr = ''
55
+ if(${(active == null ? void 0 : active.mode) === "url"}){
56
+ let queryStr='';
57
+ const result = (window.location.href || '').match(new RegExp('[?&]${(active == null ? void 0 : active.param) || "debugwhatever"}=([^&]+)', 'i'));
58
+ if (Array.isArray(result) && result.length > 1) queryStr= result[1];
59
+ if (queryStr === 'true') localStorage.setItem('${(active == null ? void 0 : active.param) || "debugwhatever"}', 'true');
60
+ }
61
+ if(${(active == null ? void 0 : active.mode) === "url" || (active == null ? void 0 : active.mode) === "storage"})
62
+ storageStr = localStorage.getItem('${(active == null ? void 0 : active.param) || "debugwhatever"}')
63
+ if (storageStr === 'true'){ showDebug=true };
64
+ `;
65
+ };
59
66
 
60
67
  // src/plugins/eruda.ts
68
+ var import_meta = {};
61
69
  var transformErudaOptions = (html, opts) => {
62
- const { debug } = opts;
70
+ const { debug, active } = opts;
63
71
  const { options, plugins, cdn = "jsdelivr", src } = opts.eruda;
64
72
  const tags = [];
65
73
  tags.push({
@@ -69,14 +77,13 @@ var transformErudaOptions = (html, opts) => {
69
77
  },
70
78
  injectTo: "head"
71
79
  });
72
- let erudaScript = `eruda.init(${JSON.stringify(options)});
73
- `;
80
+ let erudaScript = `eruda.init(${JSON.stringify(options || {})});`;
74
81
  if (plugins && plugins.length > 0) {
75
82
  if (cdn === "jsdelivr") {
76
83
  tags.push({
77
84
  tag: "script",
78
85
  attrs: {
79
- src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`))
86
+ src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`), cdn)
80
87
  },
81
88
  injectTo: "head"
82
89
  });
@@ -98,19 +105,17 @@ var transformErudaOptions = (html, opts) => {
98
105
  }
99
106
  tags.push({
100
107
  tag: "script",
101
- children: erudaScript,
108
+ children: `${debugInit(debug, active)}
109
+ if(showDebug===true){ ${erudaScript}}`,
102
110
  injectTo: "head"
103
111
  });
104
- if (debug === true) {
112
+ if (debug === true || debug === false) {
105
113
  return {
106
114
  html,
107
115
  tags
108
116
  };
109
117
  }
110
- if (debug === false) {
111
- return html;
112
- }
113
- if (process.env.NODE_ENV !== "production") {
118
+ if (!import_meta.env.PROD) {
114
119
  return {
115
120
  html,
116
121
  tags
@@ -118,7 +123,7 @@ var transformErudaOptions = (html, opts) => {
118
123
  }
119
124
  };
120
125
  var transformErudaImport = (code, opts) => {
121
- const { debug } = opts;
126
+ const { debug, active } = opts;
122
127
  const { options = {}, plugins } = opts.eruda;
123
128
  let importCode = "import eruda from 'eruda';";
124
129
  let erudaScript = `eruda.init(${JSON.stringify(options)});`;
@@ -129,14 +134,19 @@ var transformErudaImport = (code, opts) => {
129
134
  });
130
135
  }
131
136
  return {
132
- code: debug ? `/* eslint-disable */;${importCode}${erudaScript}/* eslint-enable */${code}` : code,
137
+ code: `/* eslint-disable */;
138
+ ${importCode}
139
+ ${debugInit(debug, active)}if(showDebug===true){${erudaScript}}
140
+ /* eslint-enable */
141
+ ${code}`,
133
142
  map: null
134
143
  };
135
144
  };
136
145
 
137
146
  // src/plugins/vConsole.ts
147
+ var import_meta2 = {};
138
148
  var transformVConsoleOptions = (html, opts) => {
139
- const { debug } = opts;
149
+ const { debug, active } = opts;
140
150
  const { options, cdn = "jsdelivr", src } = opts.vConsole;
141
151
  const tags = [];
142
152
  tags.push({
@@ -148,19 +158,17 @@ var transformVConsoleOptions = (html, opts) => {
148
158
  });
149
159
  tags.push({
150
160
  tag: "script",
151
- children: `var vConsole = new VConsole(${JSON.stringify(options)});`,
161
+ children: `${debugInit(debug, active)}
162
+ if(showDebug===true){var vConsole = new VConsole(${JSON.stringify(options || {})})};`,
152
163
  injectTo: "head"
153
164
  });
154
- if (debug === true) {
165
+ if (debug === true || debug === false) {
155
166
  return {
156
167
  html,
157
168
  tags
158
169
  };
159
170
  }
160
- if (debug === false) {
161
- return html;
162
- }
163
- if (process.env.NODE_ENV !== "production") {
171
+ if (!import_meta2.env.PROD) {
164
172
  return {
165
173
  html,
166
174
  tags
@@ -168,21 +176,25 @@ var transformVConsoleOptions = (html, opts) => {
168
176
  }
169
177
  };
170
178
  var transformVConsoleImport = (code, opts) => {
171
- const { debug } = opts;
179
+ const { debug, active } = opts;
172
180
  const { options = {} } = opts.vConsole;
173
181
  return {
174
- code: debug ? `/* eslint-disable */;import VConsole from 'vconsole';new VConsole(${JSON.stringify(options)});/* eslint-enable */${code}` : code,
182
+ code: `/* eslint-disable */;import VConsole from 'vconsole'; ${debugInit(debug, active)}
183
+ if(showDebug===true){new VConsole(${JSON.stringify(options)})};/* eslint-enable */${code}`,
175
184
  map: null
176
185
  };
177
186
  };
178
187
 
179
188
  // src/index.ts
180
- var src_default = (options) => {
189
+ var vDebugger = (options) => {
181
190
  const { eruda, vConsole, local, entry } = options;
182
- const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => slash(path)) : [];
191
+ const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => (0, import_vite.normalizePath)(path)) : [];
183
192
  if (eruda && vConsole) {
184
193
  throw new Error("[vite-plugin-debugger]: You'd better use only one debugger tool at a time.");
185
194
  }
195
+ if (!eruda && !vConsole) {
196
+ throw new Error("[vite-plugin-debugger]: Which one do you prefer? eruda or vConsole?");
197
+ }
186
198
  return {
187
199
  name: "vite-plugin-debugger",
188
200
  transformIndexHtml(html) {
@@ -209,5 +221,8 @@ var src_default = (options) => {
209
221
  }
210
222
  };
211
223
  };
224
+ var src_default = vDebugger;
212
225
  // Annotate the CommonJS export names for ESM import in node:
213
- 0 && (module.exports = {});
226
+ 0 && (module.exports = {
227
+ vDebugger
228
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-debugger",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A vite plugin provide the debugger tools for mobile devices.",
5
5
  "author": "jade-gjz",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "peerDependencies": {
25
25
  "eruda": "^2.4.0",
26
26
  "vconsole": "^3.14.0",
27
- "vite": "^2.0.0"
27
+ "vite": "^2.0.0 || ^3.0.0"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "eruda": {
@@ -34,18 +34,6 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "devDependencies": {
38
- "@jhqn/eslint-config-ts": "^0.0.30",
39
- "bumpp": "^8.2.1",
40
- "conventional-changelog-cli": "^2.2.2",
41
- "eruda": "https://github.com/liriliri/eruda.git",
42
- "eslint": "^8.19.0",
43
- "slash": "^4.0.0",
44
- "tsup": "^6.1.3",
45
- "typescript": "^4.7.4",
46
- "vconsole": "^3.14.6",
47
- "vite": "^2.9.13"
48
- },
49
37
  "scripts": {
50
38
  "dev": "tsup src/index.ts --dts --watch",
51
39
  "build": "tsup src/index.ts --dts",
package/README.md DELETED
@@ -1,209 +0,0 @@
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
- eruda: {
41
- // cdn: 'jsdelivr', // 'jsdelivr' | 'unpkg' | 'cdnjs'
42
- // src: 'custom CDN URL',
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)
package/README.zh_CN.md DELETED
File without changes