@uni-helper/vite-plugin-uni-pages 0.0.7 → 0.1.1
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 +76 -42
- package/dist/index.cjs +346 -247
- package/dist/index.d.ts +228 -238
- package/dist/index.mjs +367 -0
- package/package.json +20 -34
- package/README.Zh-CN.md +0 -94
- package/dist/index.cjs.map +0 -1
- package/dist/index.js +0 -261
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @uni-helper/vite-plugin-uni-pages
|
|
2
2
|
|
|
3
|
-
File system-based routing for uni-app applications using Vite
|
|
3
|
+
File system-based routing for uni-app applications using Vite.
|
|
4
|
+
|
|
5
|
+
<a href="https://www.npmjs.com/package/@uni-helper/vite-plugin-uni-pages"><img src="https://img.shields.io/npm/v/@uni-helper/vite-plugin-uni-pages" alt="NPM version"></a></p>
|
|
4
6
|
|
|
5
7
|
English | [简体中文](./README.Zh-CN.md)
|
|
6
8
|
|
|
@@ -14,52 +16,57 @@ pnpm i -D @uni-helper/vite-plugin-uni-pages
|
|
|
14
16
|
|
|
15
17
|
```ts
|
|
16
18
|
// vite.config.ts
|
|
17
|
-
import { defineConfig } from
|
|
18
|
-
import Uni from
|
|
19
|
-
import UniPages from
|
|
19
|
+
import { defineConfig } from 'vite'
|
|
20
|
+
import Uni from '@dcloudio/vite-plugin-uni'
|
|
21
|
+
import UniPages from '@uni-helper/vite-plugin-uni-pages'
|
|
20
22
|
// It is recommended to put it in front of Uni
|
|
21
23
|
export default defineConfig({
|
|
22
24
|
plugins: [UniPages(), Uni()],
|
|
23
|
-
})
|
|
25
|
+
})
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
Define global properties in `pages.config.(ts|mts|cts|js|cjs|mjs|json)`
|
|
28
|
+
Define global properties in `pages.config.(ts|mts|cts|js|cjs|mjs|json)`, You can use like `#ifdef H5` in the file.
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
// pages.config.ts
|
|
30
|
-
import {
|
|
32
|
+
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
|
|
31
33
|
|
|
32
|
-
export default
|
|
33
|
-
// You can also
|
|
34
|
-
pages: []
|
|
34
|
+
export default defineUniPages({
|
|
35
|
+
// You can also define pages fields, which have the highest priority.priority.
|
|
36
|
+
pages: [],
|
|
35
37
|
globalStyle: {
|
|
36
|
-
navigationBarTextStyle:
|
|
37
|
-
navigationBarTitleText:
|
|
38
|
-
navigationBarBackgroundColor: "#F8F8F8",
|
|
39
|
-
backgroundColor: "#F8F8F8",
|
|
38
|
+
navigationBarTextStyle: 'black',
|
|
39
|
+
navigationBarTitleText: '@uni-helper',
|
|
40
40
|
},
|
|
41
|
-
})
|
|
41
|
+
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Now all pages will be found automatically!
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
### SFC custom block for Route Data
|
|
47
|
+
|
|
48
|
+
Add route meta to the route by adding a `<route>` block to the SFC. This will be
|
|
49
|
+
directly added to the route after it is generated, and will override it.
|
|
50
|
+
|
|
51
|
+
You can specific a parser to use using `<route lang="yaml">`, or set a default
|
|
52
|
+
parser using `routeBlockLang` option.
|
|
53
|
+
|
|
54
|
+
- **Supported parser:** JSON, JSON5, YAML
|
|
55
|
+
- **Default:** JSON5
|
|
47
56
|
|
|
48
|
-
```
|
|
57
|
+
```html
|
|
49
58
|
<!-- index.vue -->
|
|
50
59
|
<!-- use type to set index -->
|
|
51
|
-
<route
|
|
60
|
+
<route type="home">
|
|
52
61
|
{
|
|
53
62
|
"style": { "navigationBarTitleText": "@uni-helper" }
|
|
54
63
|
}
|
|
55
64
|
</route>
|
|
56
65
|
|
|
57
66
|
<!-- other.vue -->
|
|
58
|
-
<route lang="
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"any-meta-data": "hello"
|
|
62
|
-
}
|
|
67
|
+
<route lang="yaml">
|
|
68
|
+
style:
|
|
69
|
+
navigationBarTitleText: "@uni-helper"
|
|
63
70
|
</route>
|
|
64
71
|
```
|
|
65
72
|
|
|
@@ -67,34 +74,61 @@ Import the virtual module to access the metadata of all pages
|
|
|
67
74
|
|
|
68
75
|
```ts
|
|
69
76
|
/// <reference types="@uni-helper/vite-plugin-uni-pages/client" />
|
|
70
|
-
import { pages } from
|
|
71
|
-
console.log(pages)
|
|
77
|
+
import { pages } from 'virtual:uni-pages'
|
|
78
|
+
console.log(pages)
|
|
72
79
|
```
|
|
73
80
|
|
|
74
81
|
## Configuration
|
|
75
82
|
|
|
76
|
-
see [types.ts](./src/types.ts)
|
|
77
|
-
|
|
78
|
-
## Hooks
|
|
79
|
-
|
|
80
|
-
You can not use like `#ifdef H5` in `pages.json`, but use [hooks](./src/types.ts) to change pagesMeta.
|
|
81
|
-
|
|
82
83
|
```ts
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
export interface Options {
|
|
85
|
+
/**
|
|
86
|
+
* Whether to scan and merge pages in pages.json
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
89
|
+
mergePages: boolean
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Paths to the directory to search for page components.
|
|
93
|
+
* @default 'src/pages'
|
|
94
|
+
*/
|
|
95
|
+
dir: string
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* pages.json dir
|
|
99
|
+
* @default "src"
|
|
100
|
+
*/
|
|
101
|
+
outDir: string
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* exclude page
|
|
105
|
+
* @default []
|
|
106
|
+
*/
|
|
107
|
+
exclude: string[]
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
|
|
111
|
+
* @default 'json5'
|
|
112
|
+
*/
|
|
113
|
+
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml'
|
|
114
|
+
|
|
115
|
+
onBeforeLoadUserConfig: (ctx: PageContext) => void
|
|
116
|
+
onAfterLoadUserConfig: (ctx: PageContext) => void
|
|
117
|
+
onBeforeScanPages: (ctx: PageContext) => void
|
|
118
|
+
onAfterScanPages: (ctx: PageContext) => void
|
|
119
|
+
onBeforeMergePageMetaData: (ctx: PageContext) => void
|
|
120
|
+
onAfterMergePageMetaData: (ctx: PageContext) => void
|
|
121
|
+
onBeforeWriteFile: (ctx: PageContext) => void
|
|
122
|
+
onAfterWriteFile: (ctx: PageContext) => void
|
|
123
|
+
}
|
|
90
124
|
```
|
|
91
125
|
|
|
92
|
-
This is a good alternative to conditional compilation, you can also use `exclude` in `vite.config.ts`
|
|
93
|
-
|
|
94
|
-
How? console the `process.env` and found `UNI_*`, you can do this!
|
|
95
|
-
|
|
96
126
|
## TODO
|
|
97
127
|
|
|
98
128
|
- [ ] only update the changed page
|
|
99
129
|
- [x] [vite-plugin-uni-middleware](https://github.com/uni-helper/vite-plugin-uni-middleware)
|
|
100
130
|
- [x] pages [type](./src/config/types.ts)
|
|
131
|
+
|
|
132
|
+
## Acknowledgement
|
|
133
|
+
|
|
134
|
+
- [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages.git)
|