@code-inspector/vite 1.1.0
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 +393 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +93 -0
- package/package.json +54 -0
- package/types/index.d.ts +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://github.com/zh-lx/code-inspector/assets/73059627/842c3e88-dca7-4743-854c-d61093d3d34f" width="160px" style="margin-bottom: 12px;" />
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<h2>code-inspector</h2>
|
|
6
|
+
<a href="https://inspector.fe-dev.cn">ไธญๆๆๆกฃ</a> | <a href="https://inspector.fe-dev.cn/en">Documentation</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/code-inspector-plugin)
|
|
10
|
+
[](https://github.com/zh-lx/code-inspector)
|
|
11
|
+
[](https://npmcharts.netlify.app/compare/code-inspector-plugin?minimal=true)
|
|
12
|
+
[](https://opensource.org/licenses/MIT)
|
|
13
|
+
[](https://github.com/zh-lx/code-inspector)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<hr />
|
|
18
|
+
|
|
19
|
+
## ๐ Introduction
|
|
20
|
+
|
|
21
|
+
Click the element on the page, it can automatically open the code editor and position the cursor to the source code of the element.
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
## ๐ป Try it out online
|
|
26
|
+
|
|
27
|
+
- [vue online demo](https://stackblitz.com/edit/vitejs-vite-4pseos?file=vite.config.ts)
|
|
28
|
+
- [react online demo](https://stackblitz.com/edit/vitejs-vite-svtwrr?file=vite.config.ts)
|
|
29
|
+
- [preact online demo](https://stackblitz.com/edit/vitejs-vite-iyawbf?file=vite.config.ts)
|
|
30
|
+
- [solid online demo](https://stackblitz.com/edit/solidjs-templates-6u76jn?file=vite.config.ts)
|
|
31
|
+
- [qwik online demo](https://stackblitz.com/edit/vitejs-vite-antzds?file=vite.config.ts)
|
|
32
|
+
- [svelte online demo](https://stackblitz.com/edit/vitejs-vite-zoncqr?file=vite.config.ts)
|
|
33
|
+
- [astro online demo](https://stackblitz.com/edit/withastro-astro-f5xq1t?file=astro.config.mjs)
|
|
34
|
+
|
|
35
|
+
## ๐จ Support
|
|
36
|
+
|
|
37
|
+
The following are which compilers, web frameworks and editors we supported now:
|
|
38
|
+
|
|
39
|
+
- The following bundlers are currently supported:<br />
|
|
40
|
+
โ
webpack<br />
|
|
41
|
+
โ
vite<br />
|
|
42
|
+
โ
rspack / rsbuild<br />
|
|
43
|
+
โ
farm<br />
|
|
44
|
+
โ
esbuild<br />
|
|
45
|
+
โ
turbopack<br />
|
|
46
|
+
โ
mako<br />
|
|
47
|
+
- The following Web frameworks are currently supported:<br />
|
|
48
|
+
โ
vue2 / vue3 / nuxt<br />
|
|
49
|
+
โ
react / nextjs / umijs<br />
|
|
50
|
+
โ
preact<br />
|
|
51
|
+
โ
solid<br />
|
|
52
|
+
โ
qwik<br />
|
|
53
|
+
โ
svelte<br />
|
|
54
|
+
โ
astro<br />
|
|
55
|
+
- The following code editors are currently supported:<br />
|
|
56
|
+
[VSCode](https://code.visualstudio.com/) | [Cursor](https://www.cursor.com/) | [Windsurf](https://codeium.com/windsurf) | [WebStorm](https://www.jetbrains.com/webstorm/) | [Atom](https://atom.io/) | [HBuilderX](https://www.dcloud.io/hbuilderx.html) | [PhpStorm](https://www.jetbrains.com/phpstorm/) | [PyCharm](https://www.jetbrains.com/pycharm/) | [IntelliJ IDEA](https://www.jetbrains.com/idea/) | [and Others](https://inspector.fe-dev.cn/en/guide/ide.html)
|
|
57
|
+
|
|
58
|
+
## ๐ Install
|
|
59
|
+
|
|
60
|
+
```perl
|
|
61
|
+
npm i code-inspector-plugin -D
|
|
62
|
+
# or
|
|
63
|
+
yarn add code-inspector-plugin -D
|
|
64
|
+
# or
|
|
65
|
+
pnpm add code-inspector-plugin -D
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## ๐ Usage
|
|
69
|
+
|
|
70
|
+
Please check here for more usage information: [code-inspector-plugin configuration](https://inspector.fe-dev.cn/en/guide/start.html#configuration)
|
|
71
|
+
|
|
72
|
+
- 1.Configuring Build Tools
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary>Click to expand configuration about: <b>webpack</b></summary>
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
// webpack.config.js
|
|
79
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
80
|
+
|
|
81
|
+
module.exports = () => ({
|
|
82
|
+
plugins: [
|
|
83
|
+
codeInspectorPlugin({
|
|
84
|
+
bundler: 'webpack',
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
</details>
|
|
91
|
+
|
|
92
|
+
<details>
|
|
93
|
+
<summary>Click to expand configuration about: <b>vite</b></summary>
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// vite.config.js
|
|
97
|
+
import { defineConfig } from 'vite';
|
|
98
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
plugins: [
|
|
102
|
+
codeInspectorPlugin({
|
|
103
|
+
bundler: 'vite',
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
<details>
|
|
112
|
+
<summary>Click to expand configuration about: <b>rspack</b></summary>
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
// rspack.config.js
|
|
116
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
117
|
+
|
|
118
|
+
module.exports = {
|
|
119
|
+
// other config...
|
|
120
|
+
plugins: [
|
|
121
|
+
codeInspectorPlugin({
|
|
122
|
+
bundler: 'rspack',
|
|
123
|
+
}),
|
|
124
|
+
// other plugins...
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
<details>
|
|
132
|
+
<summary>Click to expand configuration about: <b>rsbuild</b></summary>
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// rsbuild.config.js
|
|
136
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
137
|
+
|
|
138
|
+
module.exports = {
|
|
139
|
+
// other config...
|
|
140
|
+
tools: {
|
|
141
|
+
rspack: {
|
|
142
|
+
plugins: [
|
|
143
|
+
codeInspectorPlugin({
|
|
144
|
+
bundler: 'rspack',
|
|
145
|
+
}),
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
</details>
|
|
153
|
+
|
|
154
|
+
<details>
|
|
155
|
+
<summary>Click to expand configuration about: <b>esbuild</b></summary>
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// esbuild.config.js
|
|
159
|
+
const esbuild = require('esbuild');
|
|
160
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
161
|
+
|
|
162
|
+
esbuild.build({
|
|
163
|
+
// other configs...
|
|
164
|
+
// [ๆณจๆ] esbuild ไธญไฝฟ็จๆถ๏ผdev ๅฝๆฐ็่ฟๅๅผ้่ชๅทฑๆ นๆฎ็ฏๅขๅคๆญ๏ผๆฌๅฐๅผๅ็็ฏๅข่ฟๅ true๏ผ็บฟไธๆๅ
่ฟๅ false
|
|
165
|
+
plugins: [codeInspectorPlugin({ bundler: 'esbuild', dev: () => true })],
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
</details>
|
|
170
|
+
|
|
171
|
+
<details>
|
|
172
|
+
<summary>Click to expand configuration about: <b>farm</b></summary>
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
// farm.config.js
|
|
176
|
+
import { defineConfig } from '@farmfe/core';
|
|
177
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
178
|
+
|
|
179
|
+
export default defineConfig({
|
|
180
|
+
vitePlugins: [
|
|
181
|
+
codeInspectorPlugin({
|
|
182
|
+
bundler: 'vite',
|
|
183
|
+
}),
|
|
184
|
+
// ...other code
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
191
|
+
<details>
|
|
192
|
+
<summary>Click to expand configuration about: <b>vue-cli</b></summary>
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
// vue.config.js
|
|
196
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
197
|
+
|
|
198
|
+
module.exports = {
|
|
199
|
+
// ...other code
|
|
200
|
+
chainWebpack: (config) => {
|
|
201
|
+
config.plugin('code-inspector-plugin').use(
|
|
202
|
+
codeInspectorPlugin({
|
|
203
|
+
bundler: 'webpack',
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
</details>
|
|
211
|
+
|
|
212
|
+
<details>
|
|
213
|
+
<summary>Click to expand configuration about: <b>nuxt</b></summary>
|
|
214
|
+
|
|
215
|
+
- For nuxt3.x :
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
// nuxt.config.js
|
|
219
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
220
|
+
|
|
221
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
222
|
+
export default defineNuxtConfig({
|
|
223
|
+
vite: {
|
|
224
|
+
plugins: [codeInspectorPlugin({ bundler: 'vite' })],
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
- For nuxt2.x :
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
// nuxt.config.js
|
|
233
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
234
|
+
|
|
235
|
+
export default {
|
|
236
|
+
build: {
|
|
237
|
+
extend(config) {
|
|
238
|
+
config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }));
|
|
239
|
+
return config;
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
</details>
|
|
246
|
+
|
|
247
|
+
<details>
|
|
248
|
+
<summary>Click to expand configuration about: <b>next.js</b></summary>
|
|
249
|
+
|
|
250
|
+
- For next.js(<= 14.x):
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
// next.config.js
|
|
254
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
255
|
+
|
|
256
|
+
const nextConfig = {
|
|
257
|
+
webpack: (config, { dev, isServer }) => {
|
|
258
|
+
config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }));
|
|
259
|
+
return config;
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
module.exports = nextConfig;
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
- For next.js(15.0.x ~ 15.2.x):
|
|
267
|
+
|
|
268
|
+
```js
|
|
269
|
+
import type { NextConfig } from 'next';
|
|
270
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
271
|
+
|
|
272
|
+
const nextConfig: NextConfig = {
|
|
273
|
+
experimental: {
|
|
274
|
+
turbo: {
|
|
275
|
+
rules: codeInspectorPlugin({
|
|
276
|
+
bundler: 'turbopack',
|
|
277
|
+
}),
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export default nextConfig;
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
- For next.js(>= 15.3.x):
|
|
286
|
+
|
|
287
|
+
```js
|
|
288
|
+
// next.config.js
|
|
289
|
+
import type { NextConfig } from 'next';
|
|
290
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
291
|
+
|
|
292
|
+
const nextConfig: NextConfig = {
|
|
293
|
+
turbopack: {
|
|
294
|
+
rules: codeInspectorPlugin({
|
|
295
|
+
bundler: 'turbopack',
|
|
296
|
+
}),
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export default nextConfig;
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
</details>
|
|
304
|
+
|
|
305
|
+
<details>
|
|
306
|
+
<summary>Click to expand configuration about: <b>umi.js</b></summary>
|
|
307
|
+
|
|
308
|
+
- With webpack:
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
// umi.config.js or umirc.js
|
|
312
|
+
import { defineConfig } from '@umijs/max';
|
|
313
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
314
|
+
|
|
315
|
+
export default defineConfig({
|
|
316
|
+
chainWebpack(memo) {
|
|
317
|
+
memo.plugin('code-inspector-plugin').use(
|
|
318
|
+
codeInspectorPlugin({
|
|
319
|
+
bundler: 'webpack',
|
|
320
|
+
})
|
|
321
|
+
);
|
|
322
|
+
},
|
|
323
|
+
// other config
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
- With mako:
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
// .umirc.ts
|
|
331
|
+
import { defineConfig } from 'umi';
|
|
332
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
333
|
+
|
|
334
|
+
export default defineConfig({
|
|
335
|
+
// other config...
|
|
336
|
+
mako: {
|
|
337
|
+
plugins: [
|
|
338
|
+
codeInspectorPlugin({
|
|
339
|
+
bundler: 'mako',
|
|
340
|
+
}),
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
</details>
|
|
347
|
+
|
|
348
|
+
<details>
|
|
349
|
+
<summary>Click to expand configuration about: <b>astro</b></summary>
|
|
350
|
+
|
|
351
|
+
```js
|
|
352
|
+
// astro.config.mjs
|
|
353
|
+
import { defineConfig } from 'astro/config';
|
|
354
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
355
|
+
|
|
356
|
+
export default defineConfig({
|
|
357
|
+
vite: {
|
|
358
|
+
plugins: [codeInspectorPlugin({ bundler: 'vite' })],
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
</details>
|
|
364
|
+
|
|
365
|
+
- 2.Using the function
|
|
366
|
+
|
|
367
|
+
Now you can enjoy using it!~
|
|
368
|
+
|
|
369
|
+
When pressing the combination keys on the page, moving the mouse over the page will display a mask layer on the DOM with relevant information. Clicking will automatically open the IDE and position the cursor to the corresponding code location. (The default combination keys for Mac are `Option + Shift`; for Windows, it's `Alt + Shift`, and the browser console will output related combination key prompts)
|
|
370
|
+
|
|
371
|
+
<img src="https://cdn.jsdelivr.net/gh/zh-lx/static-img/code-inspector/console-success.png" width="700px" />
|
|
372
|
+
|
|
373
|
+
## ๐จโ๐ป Contributors
|
|
374
|
+
|
|
375
|
+
Special thanks to the contributors of this project:<br />
|
|
376
|
+
|
|
377
|
+
<img src="https://contrib.rocks/image?repo=zh-lx/code-inspector" height="40" />
|
|
378
|
+
|
|
379
|
+
## ๐ง Communication and Feedback
|
|
380
|
+
|
|
381
|
+
For any usage issues, please leave a message below my [Twitter](https://twitter.com/zhulxing312147) post or [submit an issue](https://github.com/zh-lx/code-inspector/issues) on Github.
|
|
382
|
+
|
|
383
|
+
For Chinese users, you can join the QQ group `769748484` or add the author's WeiXin account `zhoulx1688888` for consultation and feedback:
|
|
384
|
+
|
|
385
|
+
<div style="display: flex; column-gap: 16px; row-gap: 16px; flex-wrap: wrap;">
|
|
386
|
+
<img src="https://cdn.jsdelivr.net/gh/zh-lx/static-img/code-inspector/qq-group.png" width="200" height="272" />
|
|
387
|
+
<img src="https://cdn.jsdelivr.net/gh/zh-lx/static-img/code-inspector/wx-group.jpg" width="200" height="272" />
|
|
388
|
+
<img src="https://cdn.jsdelivr.net/gh/zh-lx/static-img/code-inspector/wx-qrcode.jpg" width="200" height="272" />
|
|
389
|
+
</div>
|
|
390
|
+
|
|
391
|
+
## ๐ Sponsor
|
|
392
|
+
|
|
393
|
+
Sponsoring this project can help the author create better. If you are willing, thanks for sponsoring me through [here](https://inspector.fe-dev.cn/en/more/sponsor.html).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var P=Object.defineProperty,x=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var v=(e,t,r)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t)=>{for(var r in t||(t={}))W.call(t,r)&&v(e,r,t[r]);if(d)for(var r of d(t))j.call(t,r)&&v(e,r,t[r]);return e},f=(e,t)=>x(e,C(t));var h=(e,t,r)=>new Promise((n,a)=>{var p=l=>{try{o(r.next(l))}catch(s){a(s)}},m=l=>{try{o(r.throw(l))}catch(s){a(s)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(p,m);o((r=r.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@code-inspector/core"),T="@code-inspector/vite",b=["isJsx","isTsx","lang.jsx","lang.tsx"];function w(e){const t={port:0,entry:"",output:e.output,envDir:""};return f(g({name:T},e.enforcePre===!1?{}:{enforce:"pre"}),{apply(n,{command:a}){return!e.close&&i.isDev(e.dev,a==="serve")},configResolved(n){t.envDir=n.envDir||n.root},transform(n,a){return h(this,null,function*(){if(i.isExcludedFile(a,e))return n;n=yield i.getCodeWithWebComponent({options:e,file:a,code:n,record:t});const{escapeTags:p=[],mappings:m}=e,[o,l]=a.split("?",2);let s=i.normalizePath(o);s=i.getMappingFilePath(s,m);const c=new URLSearchParams(l);if(e.match&&!e.match.test(s))return n;let u="";return i.isJsTypeFile(s)||s.endsWith(".vue")&&(b.some(y=>c.get(y)!==null)||c.get("lang")==="tsx"||c.get("lang")==="jsx")?u="jsx":s.endsWith(".html")&&c.get("type")==="template"&&c.has("vue")||s.endsWith(".vue")&&c.get("type")!=="style"&&c.get("raw")===null?u="vue":s.endsWith(".svelte")&&(u="svelte"),u?i.transformCode({content:n,filePath:s,fileType:u,escapeTags:p,pathType:e.pathType}):n})},transformIndexHtml(n){return h(this,null,function*(){const a=yield i.getCodeWithWebComponent({options:f(g({},e),{importClient:"code"}),file:"main.js",code:"",record:t,inject:!0});return n.replace("<head>",'<head><script type="module">\n'.concat(a,"\n<\/script>"))})}})}exports.ViteCodeInspectorPlugin=w;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var x = Object.defineProperty, P = Object.defineProperties;
|
|
2
|
+
var j = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var g = Object.getOwnPropertySymbols;
|
|
4
|
+
var T = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var v = (e, t, r) => t in e ? x(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, f = (e, t) => {
|
|
6
|
+
for (var r in t || (t = {}))
|
|
7
|
+
T.call(t, r) && v(e, r, t[r]);
|
|
8
|
+
if (g)
|
|
9
|
+
for (var r of g(t))
|
|
10
|
+
W.call(t, r) && v(e, r, t[r]);
|
|
11
|
+
return e;
|
|
12
|
+
}, h = (e, t) => P(e, j(t));
|
|
13
|
+
var o = (e, t, r) => new Promise((s, a) => {
|
|
14
|
+
var p = (l) => {
|
|
15
|
+
try {
|
|
16
|
+
u(r.next(l));
|
|
17
|
+
} catch (n) {
|
|
18
|
+
a(n);
|
|
19
|
+
}
|
|
20
|
+
}, m = (l) => {
|
|
21
|
+
try {
|
|
22
|
+
u(r.throw(l));
|
|
23
|
+
} catch (n) {
|
|
24
|
+
a(n);
|
|
25
|
+
}
|
|
26
|
+
}, u = (l) => l.done ? s(l.value) : Promise.resolve(l.value).then(p, m);
|
|
27
|
+
u((r = r.apply(e, t)).next());
|
|
28
|
+
});
|
|
29
|
+
import { isDev as C, isExcludedFile as w, getCodeWithWebComponent as d, normalizePath as D, getMappingFilePath as F, isJsTypeFile as I, transformCode as J } from "@code-inspector/core";
|
|
30
|
+
const L = "@code-inspector/vite", R = ["isJsx", "isTsx", "lang.jsx", "lang.tsx"];
|
|
31
|
+
function q(e) {
|
|
32
|
+
const t = {
|
|
33
|
+
port: 0,
|
|
34
|
+
entry: "",
|
|
35
|
+
output: e.output,
|
|
36
|
+
envDir: ""
|
|
37
|
+
};
|
|
38
|
+
return h(f({
|
|
39
|
+
name: L
|
|
40
|
+
}, e.enforcePre === !1 ? {} : { enforce: "pre" }), {
|
|
41
|
+
apply(s, { command: a }) {
|
|
42
|
+
return !e.close && C(e.dev, a === "serve");
|
|
43
|
+
},
|
|
44
|
+
configResolved(s) {
|
|
45
|
+
t.envDir = s.envDir || s.root;
|
|
46
|
+
},
|
|
47
|
+
transform(s, a) {
|
|
48
|
+
return o(this, null, function* () {
|
|
49
|
+
if (w(a, e))
|
|
50
|
+
return s;
|
|
51
|
+
s = yield d({
|
|
52
|
+
options: e,
|
|
53
|
+
file: a,
|
|
54
|
+
code: s,
|
|
55
|
+
record: t
|
|
56
|
+
});
|
|
57
|
+
const { escapeTags: p = [], mappings: m } = e, [u, l] = a.split("?", 2);
|
|
58
|
+
let n = D(u);
|
|
59
|
+
n = F(n, m);
|
|
60
|
+
const i = new URLSearchParams(l);
|
|
61
|
+
if (e.match && !e.match.test(n))
|
|
62
|
+
return s;
|
|
63
|
+
let c = "";
|
|
64
|
+
return I(n) || n.endsWith(".vue") && (R.some((y) => i.get(y) !== null) || i.get("lang") === "tsx" || i.get("lang") === "jsx") ? c = "jsx" : n.endsWith(".html") && i.get("type") === "template" && i.has("vue") || n.endsWith(".vue") && i.get("type") !== "style" && i.get("raw") === null ? c = "vue" : n.endsWith(".svelte") && (c = "svelte"), c ? J({
|
|
65
|
+
content: s,
|
|
66
|
+
filePath: n,
|
|
67
|
+
fileType: c,
|
|
68
|
+
escapeTags: p,
|
|
69
|
+
pathType: e.pathType
|
|
70
|
+
}) : s;
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
// ่ฟฝๅ ๅฐ html ไธญ๏ผ้้
MPA ้กน็ฎ
|
|
74
|
+
transformIndexHtml(s) {
|
|
75
|
+
return o(this, null, function* () {
|
|
76
|
+
const a = yield d({
|
|
77
|
+
options: h(f({}, e), { importClient: "code" }),
|
|
78
|
+
file: "main.js",
|
|
79
|
+
code: "",
|
|
80
|
+
record: t,
|
|
81
|
+
inject: !0
|
|
82
|
+
});
|
|
83
|
+
return s.replace(
|
|
84
|
+
"<head>",
|
|
85
|
+
'<head><script type="module">\n'.concat(a, "\n<\/script>")
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
q as ViteCodeInspectorPlugin
|
|
93
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@code-inspector/vite",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"typings": "./types/index.d.ts",
|
|
7
|
+
"repository": "git@github.com:zh-lx/code-inspector.git",
|
|
8
|
+
"author": "zh-lx <18366276315@163.com>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://inspector.fe-dev.cn/en",
|
|
11
|
+
"description": "Click the dom on the page, it will open your IDE and position the cursor to the source code location of the dom.",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"types"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./types/index.d.ts",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"webpack",
|
|
30
|
+
"vite",
|
|
31
|
+
"plugin",
|
|
32
|
+
"vue",
|
|
33
|
+
"vscode",
|
|
34
|
+
"inspector",
|
|
35
|
+
"inspect"
|
|
36
|
+
],
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/zh-lx/code-inspector/issues"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@code-inspector/core": "workspace:*"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^16.0.1",
|
|
45
|
+
"typescript": "^4.9.3",
|
|
46
|
+
"vite": "^4.3.9"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"clear": "rimraf ./dist && rimraf ./types",
|
|
50
|
+
"build": "pnpm clear && tsc && vite build",
|
|
51
|
+
"pub": "pnpm publish",
|
|
52
|
+
"pub:beta": "pnpm publish --tag beta"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodeOptions } from '@code-inspector/core';
|
|
2
|
+
interface Options extends CodeOptions {
|
|
3
|
+
close?: boolean;
|
|
4
|
+
output: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function ViteCodeInspectorPlugin(options: Options): {
|
|
7
|
+
apply(_: any, { command }: {
|
|
8
|
+
command: any;
|
|
9
|
+
}): boolean;
|
|
10
|
+
configResolved(config: any): void;
|
|
11
|
+
transform(code: string, id: string): Promise<string>;
|
|
12
|
+
transformIndexHtml(html: any): Promise<any>;
|
|
13
|
+
enforce?: "pre";
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
export {};
|