Skip to content

Commit

Permalink
Merge pull request #17 from vadxq/dev
Browse files Browse the repository at this point in the history
feat: update type and readme
  • Loading branch information
vadxq authored Jun 27, 2023
2 parents 830b514 + 2acfc1d commit 3869d1d
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 40 deletions.
95 changes: 84 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> vite plugin for vconsole
>
> A plugin for Vite2+ that helps developers easily use the functions of VConsole in various environments.
> A plugin for Vite v2+ that helps developers easily use the functions of VConsole in various environments.
**English** | [中文](./README.zh_CN.md)

Expand Down Expand Up @@ -68,7 +68,6 @@ export default defineConfig({
vue(),
viteVConsole({
entry: path.resolve('src/main.ts'), // or you can use entry: [path.resolve('src/main.ts')]
localEnabled: true,
enabled: true,
config: {
maxLogNumber: 1000,
Expand All @@ -93,7 +92,6 @@ export default defineConfig({
vue(),
viteVConsole({
entry: [path.resolve('src/main.ts')], // entry for each page, different from the above
localEnabled: true,
enabled: true,
config: {
maxLogNumber: 1000,
Expand All @@ -118,7 +116,6 @@ export default defineConfig({
reactRefresh(),
viteVConsole({
entry: path.resolve('src/main.tsx'),
localEnabled: true,
enabled: true,
config: {
maxLogNumber: 1000,
Expand All @@ -145,7 +142,6 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
vue(),
viteVConsole({
entry: [path.resolve('src/main.ts')], // entry file
localEnabled: command === 'serve', // dev environment
enabled: command !== 'serve' || mode === 'test', // build production
config: { // vconsole options
maxLogNumber: 1000
Expand All @@ -157,16 +153,76 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
};
```

- vConsole plugin config

```javascript
viteVConsole({
entry: path.resolve('src/main.ts'),
enabled: true,
config: {
theme: 'dark',
onReady() {
console.log(23333);
}
},
plugin: [
{
id: 'my_plugin',
name: 'MyPlugin',
event: [
{
eventName: 'init',
callback: function () {
console.log('My plugin init');
}
},
{
eventName: 'renderTab',
callback: function () {
console.log('My plugin renderTab');
}
}
]
},
{
id: 'my_plugin2',
name: 'MyPlugin2',
event: [
{
eventName: 'init',
callback: function () {
console.log('My plugin2 init');
}
},
{
eventName: 'renderTab',
callback: function () {
console.log('My plugin2 renderTab');
}
}
]
}
]
})
```

### viteVConsole Options

```ts
/// <reference types="vconsole" />

{
entry: string | string[]; // entry file require
localEnabled?: boolean;
enabled?: boolean;
config?: VConsoleOptions
plugin?: {
id: string;
name: string;
event: {
eventName: string;
callback: (data?: any) => void;
}[]
}[]
}
```

Expand All @@ -179,17 +235,30 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {

must support. Supports multiple entries when it is an array.

### localEnabled
### enabled

**type:** `boolean`

**default:** `false`
**default:** `true`

### enabled
### config

**type:** `boolean`
**type:**: `VConsoleOptions`

**default:** `true`
### plugin

**type:**

```type
{
id: string;
name: string;
event: {
eventName: string;
callback: (data?: any) => void;
}[]
}[]
```

## Typescript

Expand Down Expand Up @@ -219,6 +288,10 @@ Update to V1.3.0+ version, can support VConsole Functions Configuration.

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

## Support VConsole Plugin Configuration

Update to V2.0.0+ version, can support VConsole Plugin Configuration.

## License

[MIT](LICENSE)
92 changes: 79 additions & 13 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> vite plugin for vconsole
>
> 一个适用于Vite2+的插件,帮助开发者在各个环境下方便使用VConsole的功能。可以方便配置区分环境,根据环境动态加载VConsole,支持多页面配置。
> 一个适用于 Vite v2+的插件,帮助开发者在各个环境下方便使用VConsole的功能。可以方便配置区分环境,根据环境动态加载VConsole,支持多页面配置。
**中文** | [English](./README.md)

Expand Down Expand Up @@ -70,8 +70,7 @@ export default defineConfig({
vue(),
viteVConsole({
entry: path.resolve('src/main.ts'), // 或者可以使用这个配置: [path.resolve('src/main.ts')]
localEnabled: true,
enabled: true,
enabled: true, // 可自行结合 mode 和 command 进行判断
config: {
maxLogNumber: 1000,
theme: 'dark'
Expand All @@ -95,8 +94,7 @@ export default defineConfig({
vue(),
viteVConsole({
entry: [path.resolve('src/main.ts')], // 每个页面的入口文件,和上面不一样的地方,这里是一个数组
localEnabled: true,
enabled: true,
enabled: true, // 可自行结合 mode 和 command 进行判断
config: {
maxLogNumber: 1000,
theme: 'dark'
Expand All @@ -120,8 +118,7 @@ export default defineConfig({
reactRefresh(),
viteVConsole({
entry: path.resolve('src/main.tsx'),
localEnabled: true,
enabled: true,
enabled: true, // 可自行结合 mode 和 command 进行判断
config: {
maxLogNumber: 1000,
theme: 'dark'
Expand All @@ -146,7 +143,6 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
vue(),
viteVConsole({
entry: [path.resolve('src/main.ts')], // 入口文件
localEnabled: command === 'serve', // serve开发环境下
enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包
config: { // vconsole 配置项
maxLogNumber: 1000
Expand All @@ -158,6 +154,59 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
};
```

- 自定义vConsole插件

```javascript
viteVConsole({
entry: path.resolve('src/main.ts'),
enabled: true,
config: {
theme: 'dark',
onReady() {
console.log(23333);
}
},
plugin: [
{
id: 'my_plugin',
name: 'MyPlugin',
event: [
{
eventName: 'init',
callback: function () {
console.log('My plugin init');
}
},
{
eventName: 'renderTab',
callback: function () {
console.log('My plugin renderTab');
}
}
]
},
{
id: 'my_plugin2',
name: 'MyPlugin2',
event: [
{
eventName: 'init',
callback: function () {
console.log('My plugin2 init');
}
},
{
eventName: 'renderTab',
callback: function () {
console.log('My plugin2 renderTab');
}
}
]
}
]
})
```

## 配置

### entry
Expand All @@ -167,17 +216,30 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {

必须提供,支持多入口。

### localEnabled
### enabled

**type:** `boolean`

**default:** `false`
**default:** `true`

### enabled
### config

**type:** `boolean`
**type:**: `VConsoleOptions`

**default:** `true`
### plugin

**type:**

```type
{
id: string;
name: string;
event: {
eventName: string;
callback: (data?: any) => void;
}[]
}[]
```

## Typescript

Expand Down Expand Up @@ -207,6 +269,10 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {

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

## 支持VConsole自定义插件和配置参数调整

更新至V2.0.0+版本,可以配置VConsole定义插件啦~

## License

[MIT](LICENSE)
2 changes: 1 addition & 1 deletion example/react-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import { viteVConsole } from '../../src';
import { viteVConsole } from '../../src/main';
import * as path from 'path';

// https://vitejs.dev/config/
Expand Down
1 change: 1 addition & 0 deletions example/vue-demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
dist-ssr
*.local
pnpm-lock.yaml
12 changes: 6 additions & 6 deletions example/vue-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"serve": "vite preview"
},
"dependencies": {
"vconsole": "^3.6.1",
"vue": "^3.0.5"
"vconsole": "^3.15.1",
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.2.2",
"@vue/compiler-sfc": "^3.0.5",
"typescript": "^4.1.3",
"vite": "^2.2.3",
"@vitejs/plugin-vue": "^2.3.4",
"@vue/compiler-sfc": "^3.3.4",
"typescript": "^4.9.5",
"vite": "^3.2.7",
"vue-tsc": "^0.0.24"
}
}
2 changes: 1 addition & 1 deletion example/vue-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { viteVConsole } from '../../src/main';
import viteVConsole from '../../src/main';
import * as path from 'path';

// https://vitejs.dev/config/
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-vconsole",
"version": "1.3.1",
"version": "2.0.0-beta.0",
"description": "vite plugin vconsole",
"main": "dist/index.js",
"exports": {
Expand Down Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@types/node": "^20.3.2",
"@types/node": "^18.3.2",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"conventional-changelog-cli": "^3.0.0",
Expand Down
Loading

0 comments on commit 3869d1d

Please sign in to comment.