Skip to content

Commit b390a87

Browse files
authored
Merge pull request #18 from vadxq/dev
feat: custom hide
2 parents 9376ec0 + 9c888a5 commit b390a87

File tree

6 files changed

+77
-18
lines changed

6 files changed

+77
-18
lines changed

README.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
**vite version:** >=2.0.0
1818

1919
```bash
20-
yarn add vconsole
21-
# or
20+
# npm
21+
npm i vite-plugin-vconsole -D
2222
npm i vconsole -S
23-
```
2423

25-
```bash
24+
# yarn
25+
yarn add vconsole
2626
yarn add vite-plugin-vconsole -D
27-
# or
28-
npm i vite-plugin-vconsole -D
27+
28+
# pnpm
29+
pnpm add vconsole
30+
pnpm add -D vite-plugin-vconsole
2931
```
3032

3133
## Example
@@ -57,6 +59,7 @@ yarn dev
5759
- **Vue** sample config
5860

5961
```ts
62+
// tips: If the reference path hint does not exist, you can import the @types/node package
6063
import { defineConfig } from 'vite';
6164
import vue from '@vitejs/plugin-vue';
6265
import { viteVConsole } from 'vite-plugin-vconsole';
@@ -226,6 +229,23 @@ viteVConsole({
226229
}
227230
```
228231

232+
- A custom rule that triggers destruction, see the question request: [How to judge page userAgent to choose whether to load vconsole](https://github.com/vadxq/vite-plugin-vconsole/issues/12)
233+
234+
```javascript
235+
// customHide: A piece of executable code, used to start some APIs on the browser side.
236+
viteVConsole({
237+
entry: path.resolve('src/main.ts'),
238+
enabled: true,
239+
customHide: `/chrome\\/([\\d\\.]+)/.test(navigator.userAgent.toLowerCase())`,
240+
config: {
241+
theme: 'dark',
242+
onReady() {
243+
console.log(23333);
244+
}
245+
},
246+
})
247+
```
248+
229249
## Options
230250

231251
### entry
@@ -260,6 +280,10 @@ must support. Supports multiple entries when it is an array.
260280
}[]
261281
```
262282

283+
### customHide
284+
285+
**type:**: String
286+
263287
## Typescript
264288

265289
Add a reference to `vconsole`
@@ -288,9 +312,9 @@ Update to V1.3.0+ version, can support VConsole Functions Configuration.
288312

289313
Many thanks to [@KeJunMao](https://github.com/KeJunMao) for support!
290314

291-
## Support VConsole Plugin Configuration
315+
## Support VConsole Plugin Configuration.Support custom destruction
292316

293-
Update to V2.0.0+ version, can support VConsole Plugin Configuration.
317+
Update to V2.0.0+ version, can support VConsole Plugin Configuration.Also supports custom destruction.
294318

295319
## License
296320

README.zh_CN.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
**vite version:** >=2.0.0
1818

1919
```bash
20-
yarn add vconsole
21-
# or
20+
# npm
21+
npm i vite-plugin-vconsole -D
2222
npm i vconsole -S
23-
```
2423

25-
```bash
24+
# yarn
25+
yarn add vconsole
2626
yarn add vite-plugin-vconsole -D
27-
# or
28-
npm i vite-plugin-vconsole -D
27+
28+
# pnpm
29+
pnpm add vconsole
30+
pnpm add -D vite-plugin-vconsole
2931
```
3032

3133
## 示例
@@ -59,6 +61,7 @@ yarn dev
5961
- **Vue** 简单配置
6062

6163
```ts
64+
// tips: 如果引用path提示不存在,可以引入@types/node包
6265
import { defineConfig } from 'vite';
6366
import vue from '@vitejs/plugin-vue';
6467
import { viteVConsole } from 'vite-plugin-vconsole';
@@ -207,6 +210,23 @@ viteVConsole({
207210
})
208211
```
209212

213+
- 自定义规则使其触发销毁,见issue需求:[如何判断页面userAgent来选择是否加载vconsole](https://github.com/vadxq/vite-plugin-vconsole/issues/12)
214+
215+
```javascript
216+
// customHide: 一段可运行代码段,用于出发在浏览器端的一些api
217+
viteVConsole({
218+
entry: path.resolve('src/main.ts'),
219+
enabled: true,
220+
customHide: `/chrome\\/([\\d\\.]+)/.test(navigator.userAgent.toLowerCase())`,
221+
config: {
222+
theme: 'dark',
223+
onReady() {
224+
console.log(23333);
225+
}
226+
},
227+
})
228+
```
229+
210230
## 配置
211231

212232
### entry
@@ -241,6 +261,10 @@ viteVConsole({
241261
}[]
242262
```
243263

264+
### customHide
265+
266+
**type:**: String
267+
244268
## Typescript
245269

246270
添加 `vconsole` 的引用
@@ -269,9 +293,9 @@ viteVConsole({
269293

270294
非常感谢[@KeJunMao](https://github.com/KeJunMao)的支持!
271295

272-
## 支持VConsole自定义插件和配置参数调整
296+
## 支持VConsole自定义插件和配置参数调整,支持自定义销毁
273297

274-
更新至V2.0.0+版本,可以配置VConsole定义插件啦~
298+
更新至V2.0.0+版本,可以配置VConsole定义插件啦~同时支持自定义销毁
275299

276300
## License
277301

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-vconsole",
3-
"version": "2.0.0-beta.1",
3+
"version": "2.0.0-beta.2",
44
"description": "vite plugin vconsole",
55
"main": "dist/main.js",
66
"exports": {

playground/vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default defineConfig({
88
viteVConsole({
99
entry: path.resolve('src/main.ts'),
1010
enabled: true,
11+
customHide: `/chrome\\/([\\d\\.]+)/.test(navigator.userAgent.toLowerCase())`,
1112
config: {
1213
theme: 'dark',
1314
onReady() {

src/main.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ const getEventItems = (
3434
};
3535

3636
export function viteVConsole(opt: viteVConsoleOptions): Plugin {
37-
const { entry, enabled = true, config = {}, plugin } = opt;
37+
const {
38+
entry,
39+
enabled = true,
40+
config = {},
41+
plugin,
42+
customHide = false
43+
} = opt;
3844

3945
// Compatible to solve the windows path problem
4046
let entryPath = Array.isArray(entry) ? entry : [entry];
@@ -67,6 +73,9 @@ export function viteVConsole(opt: viteVConsoleOptions): Plugin {
6773
)}});
6874
window.vConsole = vConsole;
6975
${plugins}
76+
if (${customHide}) {
77+
vConsole.destroy()
78+
}
7079
/* eslint-enable */${_source}`;
7180

7281
return {

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface viteVConsoleOptions {
66
localEnabled?: boolean; // serve dev enabled
77
enabled?: boolean; // enabled
88
config?: VConsoleOptions; // vconsole option
9+
customHide?: string; // custom hide rule code string
910
plugin?: {
1011
id: string;
1112
name: string;

0 commit comments

Comments
 (0)