diff --git a/.gitignore b/.gitignore
index 1058fbd..eb9553b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@ node_modules
# Build Outputs
build
-dist
\ No newline at end of file
+dist
+.idea
diff --git a/README.md b/README.md
index a736a7d..ecd9502 100644
--- a/README.md
+++ b/README.md
@@ -251,6 +251,39 @@ onMounted(() => {
+
+
+
+ (点击展开) 功能三:过滤掉不需要根组件的页面
+
+
+
+如果遇到一些不需要根组件的页面,可以设置 `excludePages` 选项来过滤
+
+> `excludePages` 选项支持采用 glob 模式进行编写
+
+```ts
+// vite.config.(js|ts)
+
+import Uni from '@dcloudio/vite-plugin-uni'
+import UniKuRoot from '@uni-ku/root'
+import { defineConfig } from 'vite'
+
+export default defineConfig({
+ plugins: [
+ UniKuRoot({
+ excludePages: [
+ 'src/exclude.vue',
+ 'src/exclude/**/*.vue'
+ ],
+ }),
+ Uni()
+ ]
+})
+```
+
+
+
### ✨ 例子
> [!TIP]
diff --git a/examples/src/pages.json b/examples/src/pages.json
index 7d00edb..a7e4e19 100644
--- a/examples/src/pages.json
+++ b/examples/src/pages.json
@@ -17,6 +17,12 @@
"style": {
"navigationBarTitleText": "uni-app"
}
+ },
+ {
+ "path": "pages/excluded",
+ "style": {
+ "navigationBarTitleText": "uni-app"
+ }
}
],
"globalStyle": {
diff --git a/examples/src/pages/excluded.vue b/examples/src/pages/excluded.vue
new file mode 100644
index 0000000..110aa7d
--- /dev/null
+++ b/examples/src/pages/excluded.vue
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+ Hello KuRoot
+
+
+ Hello v-bind css
+
+
+
+
+
+
diff --git a/examples/vite.config.ts b/examples/vite.config.ts
index fca8dca..37861c5 100644
--- a/examples/vite.config.ts
+++ b/examples/vite.config.ts
@@ -12,6 +12,7 @@ export default defineConfig({
UniKuRoot({
enabledVirtualHost: false,
rootFileName: 'KuRoot',
+ excludePages: 'src/pages/excluded.vue',
}),
Uni(),
],
diff --git a/src/index.ts b/src/index.ts
index ab99f78..e8616fe 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
import type { MagicString } from '@vue/compiler-sfc'
import type { FSWatcher } from 'chokidar'
-import type { Plugin } from 'vite'
+import type { FilterPattern, Plugin } from 'vite'
import { resolve } from 'node:path'
import process from 'node:process'
@@ -28,6 +28,14 @@ interface UniKuRootOptions {
* @default 'App.ku'
*/
rootFileName?: string
+ /**
+ * 需要排除根组件的页面,支持 glob 匹配
+ * @example
+ * ```
+ * ['src/pages/some.vue', 'src/exclude/*.vue']
+ * ```
+ */
+ excludePages?: FilterPattern
}
export default function UniKuRoot(options: UniKuRootOptions = {
@@ -71,7 +79,7 @@ export default function UniKuRoot(options: UniKuRootOptions = {
const pageId = hasPlatformPlugin ? normalizePlatformPath(id) : id
- const filterPage = createFilter(pagesJson)
+ const filterPage = createFilter(pagesJson, options.excludePages)
if (filterPage(pageId)) {
ms = await transformPage(code, options.enabledGlobalRef)
}
diff --git a/src/utils.ts b/src/utils.ts
index ddf6d20..0762805 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -22,7 +22,7 @@ export function formatPagePath(root: string, path: string) {
return normalizePath(`${join(root, path)}.vue`)
}
-export function loadPagesJson(path: string, rootPath: string) {
+export function loadPagesJson(path: string, rootPath: string): string[] {
const pagesJsonRaw = readFileSync(path, 'utf-8')
const { pages = [], subPackages = [] } = jsonParse(pagesJsonRaw)