Skip to content

Commit 67de5bd

Browse files
committed
feat: add basic nvue support
1 parent 5d823ae commit 67de5bd

File tree

7 files changed

+90
-74
lines changed

7 files changed

+90
-74
lines changed

fixtures/input/nvue.nvue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div>
3+
<h1>
4+
{{ greeting }}</h1>
5+
<button @click="incrementCounter">Click me!</button>
6+
<p>Counter: {{ counter }}</p>
7+
<web-view src="https://uni-helper.js.org"
8+
/>
9+
</div>
10+
</template>
11+
12+
<script setup>
13+
// Define reactive data and props
14+
import { ref } from '@vue/reactivity';
15+
16+
const greeting = ref('Hello, Vue 3!' + 1);
17+
let counter = ref(0)
18+
19+
// Define a function
20+
const incrementCounter = () => {
21+
counter.value++;
22+
};
23+
</script>

fixtures/output/json/nvue.nvue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// unchanged

fixtures/output/uni/nvue.nvue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup>
2+
// Define reactive data and props
3+
import { ref } from 'vue'
4+
5+
const greeting = ref(`Hello, Vue 3!${1}`)
6+
const counter = ref(0)
7+
8+
// Define a function
9+
function incrementCounter() {
10+
counter.value++
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<h1>
17+
{{ greeting }}
18+
</h1>
19+
<button @click="incrementCounter">
20+
Click me!
21+
</button>
22+
<p>Counter: {{ counter }}</p>
23+
<web-view src="https://uni-helper.js.org" />
24+
</div>
25+
</template>

src/config/uni.ts

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,32 @@
1-
import { GLOB_VUE } from '@antfu/eslint-config'
2-
import type { ConfigItem, OptionsOverrides } from '@antfu/eslint-config'
1+
import type { ConfigItem, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic } from '@antfu/eslint-config'
2+
import { pluginVue, vue } from '@antfu/eslint-config'
3+
import { GLOB_UNI } from '../globs'
34

4-
export function uni(options: OptionsOverrides = {}): ConfigItem[] {
5+
export function uni(options: OptionsHasTypeScript & OptionsOverrides & OptionsStylistic = {}): ConfigItem[] {
56
const {
67
overrides = {},
78
} = options
9+
const vueConfig = vue({ ...options })
10+
11+
const setup = vueConfig.find(v => v.name === 'antfu:vue:setup')!
12+
const rules = vueConfig.find(v => v.name === 'antfu:vue:rules')!
13+
14+
setup.name = 'uni:vue:setup'
15+
setup.plugins = {
16+
vue: pluginVue,
17+
}
18+
rules.name = 'uni:vue:rules'
19+
rules.files = [GLOB_UNI]
20+
rules.rules = {
21+
...rules.rules,
22+
'vue/component-name-in-template-casing': ['error', 'kebab-case', {
23+
registeredComponentsOnly: false,
24+
}],
25+
...overrides,
26+
}
827

928
return [
10-
{
11-
files: [GLOB_VUE],
12-
name: 'uni:vue:rules',
13-
rules: {
14-
'vue/component-name-in-template-casing': ['error', 'PascalCase', {
15-
registeredComponentsOnly: false,
16-
ignores: [
17-
// 视图
18-
'view',
19-
'scroll-view',
20-
'swiper',
21-
'match-media',
22-
'movable-area',
23-
'movable-view',
24-
'cover-view',
25-
'cover-image',
26-
// 基础
27-
'icon',
28-
'text',
29-
'rich-text',
30-
'progress',
31-
// 表单
32-
'editor',
33-
'picker',
34-
'picker-view',
35-
'slider',
36-
// 路由
37-
'navigator',
38-
// 媒体
39-
'animation-view',
40-
'camera',
41-
'image',
42-
'live-player',
43-
'live-pusher',
44-
// 地图
45-
'map',
46-
// 画布
47-
// webview
48-
'web-view',
49-
// TODO: 广告
50-
'ad',
51-
'ad-rewarded-video',
52-
'ad-fullscreen-video',
53-
'ad-interstitial',
54-
'ad-draw',
55-
'ad-content-page',
56-
// 云数据库
57-
'unicloud-db',
58-
// 页面配置
59-
'page-meta',
60-
'navigation-bar',
61-
'custom-tab-bar',
62-
// nvue 组件
63-
'barcode',
64-
'list',
65-
'cell',
66-
'recycle-list',
67-
'waterfall',
68-
'refresh',
69-
// 小程序组件
70-
'official-account',
71-
'open-data',
72-
],
73-
}],
74-
...overrides,
75-
},
76-
},
29+
setup,
30+
rules,
7731
]
7832
}

src/globs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const GLOB_UNI = '**/*.?([un])vue'

src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ export function uniHelper(options: OptionsConfig & ConfigItem = {}, ...userConfi
1818
uni: enableUni = true,
1919
uniJson = true,
2020
overrides = {},
21+
typescript: enableTypeScript = isPackageExists('typescript'),
2122
} = options
2223

24+
const stylisticOptions = options.stylistic === false
25+
? false
26+
: typeof options.stylistic === 'object'
27+
? options.stylistic
28+
: {}
29+
if (stylisticOptions && !('jsx' in stylisticOptions))
30+
stylisticOptions.jsx = options.jsx ?? true
31+
2332
const ignoreManifestJSON = isPackageExists('@uni-helper/vite-plugin-uni-manifest') || uniJson === false
2433
const ignorePagesJSON = isPackageExists('@uni-helper/vite-plugin-uni-pages') || uniJson === false
2534
options.ignores = options.ignores || []
@@ -39,14 +48,18 @@ export function uniHelper(options: OptionsConfig & ConfigItem = {}, ...userConfi
3948
userConfigs.unshift(sortThemeJson())
4049

4150
if (enableUni) {
42-
// force enable vue
43-
options.vue = true
51+
// force disable vue
52+
options.vue = false
4453
userConfigs.unshift(uni({
4554
overrides: overrides.uni,
55+
typescript: !!enableTypeScript,
56+
stylistic: stylisticOptions,
4657
}))
4758
}
4859

49-
return antfu(options, ...userConfigs)
60+
const config = antfu(options, ...userConfigs)
61+
62+
return config
5063
}
5164

5265
export default uniHelper

test/fixtures.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export default uni(
4242

4343
await execa('npx', ['eslint', '.', '--fix'], {
4444
cwd: target,
45-
stdio: 'pipe',
4645
})
4746

4847
const files = await fg('**/*', {

0 commit comments

Comments
 (0)