@univa/core 0.0.5 → 0.0.6
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 +36 -16
- package/dist/index.cjs +64 -61
- package/dist/index.js +64 -61
- package/package.json +17 -2
- package/src/client.d.ts +5 -4
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
> 🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/@univa/core)
|
|
6
|
+
[](https://www.npmjs.com/package/@univa/core)
|
|
7
|
+
[](https://bundlephobia.com/package/@univa/core)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
5
10
|
## 特性
|
|
6
11
|
|
|
7
12
|
- 📦 **开箱即用** - 零配置即可开始开发
|
|
@@ -57,8 +62,6 @@ export default defineConfig({
|
|
|
57
62
|
}
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
<br />
|
|
61
|
-
|
|
62
65
|
## 功能详解
|
|
63
66
|
|
|
64
67
|
### 自动导入
|
|
@@ -81,7 +84,7 @@ const store = useStore()
|
|
|
81
84
|
|
|
82
85
|
自动注册 `components` 目录下的组件,无需手动 import:
|
|
83
86
|
|
|
84
|
-
```
|
|
87
|
+
```text
|
|
85
88
|
src/
|
|
86
89
|
├── components/
|
|
87
90
|
│ ├── MyButton.vue
|
|
@@ -145,7 +148,12 @@ export default defineConfig({
|
|
|
145
148
|
config: {
|
|
146
149
|
tabBarMode: 'CUSTOM',
|
|
147
150
|
tabBar: {
|
|
148
|
-
list: [
|
|
151
|
+
list: [
|
|
152
|
+
{
|
|
153
|
+
pagePath: 'pages/index',
|
|
154
|
+
text: '首页',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
149
157
|
},
|
|
150
158
|
},
|
|
151
159
|
},
|
|
@@ -154,18 +162,20 @@ export default defineConfig({
|
|
|
154
162
|
})
|
|
155
163
|
```
|
|
156
164
|
|
|
157
|
-
#### 获取
|
|
165
|
+
#### 获取 Pages 配置
|
|
158
166
|
|
|
159
|
-
在组件中获取
|
|
167
|
+
在组件中获取 Pages 配置:
|
|
160
168
|
|
|
161
169
|
```typescript
|
|
162
|
-
import tabBar from 'virtual:univa-
|
|
170
|
+
import { pages, subPackages, tabBar } from 'virtual:univa-pages'
|
|
163
171
|
|
|
164
172
|
if (tabBar) {
|
|
165
173
|
console.log(tabBar.list) // TabBar 列表
|
|
166
174
|
}
|
|
167
175
|
```
|
|
168
176
|
|
|
177
|
+
**类型支持**:确保在 `tsconfig.json` 中添加了 `@univa/core/client` 类型,以获得 `virtual:univa-pages` 的类型提示。
|
|
178
|
+
|
|
169
179
|
### UnoCSS 预设
|
|
170
180
|
|
|
171
181
|
内置 UnoCSS 预设,提供开箱即用的原子化 CSS:
|
|
@@ -176,15 +186,16 @@ if (tabBar) {
|
|
|
176
186
|
- `presetLegacyCompat()` - 兼容性预设(处理低端安卓机)
|
|
177
187
|
|
|
178
188
|
**内置快捷方式**:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
|
|
190
|
+
| 快捷方式 | 展开后 |
|
|
191
|
+
|---------|--------|
|
|
192
|
+
| `border-s` | `border border-solid` |
|
|
193
|
+
| `wh-full` | `w-full h-full` |
|
|
194
|
+
| `f-c-c` | `flex justify-center items-center` |
|
|
195
|
+
| `f-col-c` | `flex-col justify-center items-center` |
|
|
196
|
+
| `flex-items` | `flex items-center` |
|
|
197
|
+
| `flex-justify` | `flex justify-center` |
|
|
198
|
+
| `flex-col` | `flex flex-col` |
|
|
188
199
|
|
|
189
200
|
**安全区域规则**:
|
|
190
201
|
```html
|
|
@@ -315,6 +326,15 @@ const config: UnivaUserConfig = {
|
|
|
315
326
|
- `@uni-ku/bundle-optimizer` - 打包优化
|
|
316
327
|
- `vite-plugin-uni-polyfill` - Polyfill
|
|
317
328
|
|
|
329
|
+
## 致谢
|
|
330
|
+
|
|
331
|
+
- 感谢 [uni-helper](https://github.com/uni-helper) 社区提供的优秀插件
|
|
332
|
+
- 感谢 [uni-ku](https://github.com/uni-ku) 提供的优秀插件
|
|
333
|
+
|
|
318
334
|
## License
|
|
319
335
|
|
|
320
336
|
MIT
|
|
337
|
+
|
|
338
|
+
## Contact
|
|
339
|
+
|
|
340
|
+
📧 Email: libre1103@163.com
|
package/dist/index.cjs
CHANGED
|
@@ -170,59 +170,78 @@ function processPageName(ctx) {
|
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
+
function processTabBar(ctx) {
|
|
174
|
+
const tabBar = ctx.pagesGlobConfig?.tabBar;
|
|
175
|
+
if (!tabBar) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const tabBarMode = ctx.pagesGlobConfig?.tabBarMode || "NATIVE";
|
|
179
|
+
if (tabBarMode === "CUSTOM") {
|
|
180
|
+
tabBar.custom = true;
|
|
181
|
+
}
|
|
182
|
+
const rawTabBarList = [];
|
|
183
|
+
if (tabBar.list && tabBar.list.length > 0) {
|
|
184
|
+
tabBar.list = tabBar.list.map((item) => {
|
|
185
|
+
rawTabBarList.push({ ...item });
|
|
186
|
+
const filtered = { ...item };
|
|
187
|
+
if (!filtered.iconPath?.startsWith("static/")) {
|
|
188
|
+
delete filtered.iconPath;
|
|
189
|
+
}
|
|
190
|
+
if (!filtered.selectedIconPath?.startsWith("static/")) {
|
|
191
|
+
delete filtered.selectedIconPath;
|
|
192
|
+
}
|
|
193
|
+
return filtered;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const clonedTabBar = { ...tabBar };
|
|
197
|
+
if (clonedTabBar.list) {
|
|
198
|
+
clonedTabBar.list = rawTabBarList;
|
|
199
|
+
}
|
|
200
|
+
return clonedTabBar;
|
|
201
|
+
}
|
|
173
202
|
function resolveUserPagesConfig(config) {
|
|
174
203
|
if (!config.tabBar) {
|
|
175
204
|
return config;
|
|
176
205
|
}
|
|
177
|
-
|
|
178
|
-
if (config.tabBarMode === "CUSTOM") {
|
|
179
|
-
tabBar.custom = true;
|
|
180
|
-
if (tabBar.list && tabBar.list.length > 0) {
|
|
181
|
-
tabBar.list = tabBar.list.map((item) => {
|
|
182
|
-
const filtered = { ...item };
|
|
183
|
-
filtered.customIconPath = filtered.iconPath;
|
|
184
|
-
filtered.customSelectedIconPath = filtered.selectedIconPath;
|
|
185
|
-
if (!filtered.iconPath?.startsWith("static/")) {
|
|
186
|
-
delete filtered.iconPath;
|
|
187
|
-
}
|
|
188
|
-
if (!filtered.selectedIconPath?.startsWith("static/")) {
|
|
189
|
-
delete filtered.selectedIconPath;
|
|
190
|
-
}
|
|
191
|
-
return filtered;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
...config,
|
|
197
|
-
tabBar
|
|
198
|
-
};
|
|
206
|
+
return config;
|
|
199
207
|
}
|
|
200
208
|
function createPagesPlugin(options) {
|
|
201
209
|
const pages = options.pages || {};
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
const MODULE_ID_VIRTUAL = "virtual:univa-pages";
|
|
211
|
+
const RESOLVED_MODULE_ID_VIRTUAL = `\0${MODULE_ID_VIRTUAL}`;
|
|
212
|
+
const virtualData = {
|
|
213
|
+
pages: [],
|
|
214
|
+
subPackages: [],
|
|
215
|
+
tabBar: null
|
|
216
|
+
};
|
|
217
|
+
const virtualModule = () => {
|
|
218
|
+
const pages2 = `export const pages = ${virtualData.pages};`;
|
|
219
|
+
const subPackages = `export const subPackages = ${virtualData.subPackages};`;
|
|
220
|
+
const tabBar = `export const tabBar = ${JSON.stringify(virtualData.tabBar)};`;
|
|
221
|
+
return [pages2, subPackages, tabBar].join("\n");
|
|
222
|
+
};
|
|
223
|
+
const tabbarPlugin = {
|
|
224
|
+
name: "vite-plugin-univa-pages",
|
|
225
|
+
enforce: "pre",
|
|
226
|
+
resolveId(id) {
|
|
227
|
+
if (id === MODULE_ID_VIRTUAL) {
|
|
228
|
+
return RESOLVED_MODULE_ID_VIRTUAL;
|
|
217
229
|
}
|
|
218
230
|
},
|
|
231
|
+
load(id) {
|
|
232
|
+
if (id === RESOLVED_MODULE_ID_VIRTUAL) {
|
|
233
|
+
return virtualModule();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
return [
|
|
238
|
+
tabbarPlugin,
|
|
219
239
|
(0, import_vite_plugin_uni_pages.default)({
|
|
220
240
|
configSource: pages.config ? {
|
|
221
241
|
files: "vite.config",
|
|
222
242
|
rewrite: () => resolveUserPagesConfig(pages.config)
|
|
223
243
|
} : {
|
|
224
|
-
files: "pages.config"
|
|
225
|
-
extensions: ["ts", "mts", "cts", "js", "cjs", "mjs", "json"]
|
|
244
|
+
files: "pages.config"
|
|
226
245
|
},
|
|
227
246
|
subPackages: [
|
|
228
247
|
...pages.subPackages || []
|
|
@@ -233,29 +252,13 @@ function createPagesPlugin(options) {
|
|
|
233
252
|
],
|
|
234
253
|
onAfterMergePageMetaData(ctx) {
|
|
235
254
|
processPageName(ctx);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const clonedTabBar = { ...tabBar };
|
|
242
|
-
if (clonedTabBar.list) {
|
|
243
|
-
clonedTabBar.list = clonedTabBar.list.map((item) => {
|
|
244
|
-
const filtered = { ...item };
|
|
245
|
-
if (filtered.customIconPath) {
|
|
246
|
-
filtered.iconPath = filtered.customIconPath;
|
|
247
|
-
delete filtered.customIconPath;
|
|
248
|
-
}
|
|
249
|
-
if (filtered.customSelectedIconPath) {
|
|
250
|
-
filtered.selectedIconPath = filtered.customSelectedIconPath;
|
|
251
|
-
delete filtered.customSelectedIconPath;
|
|
252
|
-
}
|
|
253
|
-
return filtered;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
tabBarConfig = clonedTabBar;
|
|
255
|
+
virtualData.tabBar = processTabBar(ctx);
|
|
256
|
+
},
|
|
257
|
+
onAfterWriteFile(ctx) {
|
|
258
|
+
virtualData.pages = ctx.resolveRoutes();
|
|
259
|
+
virtualData.subPackages = ctx.resolveSubRoutes();
|
|
257
260
|
},
|
|
258
|
-
dts: `${DTS_DIR}/
|
|
261
|
+
dts: `${DTS_DIR}/pages.d.ts`
|
|
259
262
|
})
|
|
260
263
|
];
|
|
261
264
|
}
|
package/dist/index.js
CHANGED
|
@@ -132,59 +132,78 @@ function processPageName(ctx) {
|
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
+
function processTabBar(ctx) {
|
|
136
|
+
const tabBar = ctx.pagesGlobConfig?.tabBar;
|
|
137
|
+
if (!tabBar) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const tabBarMode = ctx.pagesGlobConfig?.tabBarMode || "NATIVE";
|
|
141
|
+
if (tabBarMode === "CUSTOM") {
|
|
142
|
+
tabBar.custom = true;
|
|
143
|
+
}
|
|
144
|
+
const rawTabBarList = [];
|
|
145
|
+
if (tabBar.list && tabBar.list.length > 0) {
|
|
146
|
+
tabBar.list = tabBar.list.map((item) => {
|
|
147
|
+
rawTabBarList.push({ ...item });
|
|
148
|
+
const filtered = { ...item };
|
|
149
|
+
if (!filtered.iconPath?.startsWith("static/")) {
|
|
150
|
+
delete filtered.iconPath;
|
|
151
|
+
}
|
|
152
|
+
if (!filtered.selectedIconPath?.startsWith("static/")) {
|
|
153
|
+
delete filtered.selectedIconPath;
|
|
154
|
+
}
|
|
155
|
+
return filtered;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const clonedTabBar = { ...tabBar };
|
|
159
|
+
if (clonedTabBar.list) {
|
|
160
|
+
clonedTabBar.list = rawTabBarList;
|
|
161
|
+
}
|
|
162
|
+
return clonedTabBar;
|
|
163
|
+
}
|
|
135
164
|
function resolveUserPagesConfig(config) {
|
|
136
165
|
if (!config.tabBar) {
|
|
137
166
|
return config;
|
|
138
167
|
}
|
|
139
|
-
|
|
140
|
-
if (config.tabBarMode === "CUSTOM") {
|
|
141
|
-
tabBar.custom = true;
|
|
142
|
-
if (tabBar.list && tabBar.list.length > 0) {
|
|
143
|
-
tabBar.list = tabBar.list.map((item) => {
|
|
144
|
-
const filtered = { ...item };
|
|
145
|
-
filtered.customIconPath = filtered.iconPath;
|
|
146
|
-
filtered.customSelectedIconPath = filtered.selectedIconPath;
|
|
147
|
-
if (!filtered.iconPath?.startsWith("static/")) {
|
|
148
|
-
delete filtered.iconPath;
|
|
149
|
-
}
|
|
150
|
-
if (!filtered.selectedIconPath?.startsWith("static/")) {
|
|
151
|
-
delete filtered.selectedIconPath;
|
|
152
|
-
}
|
|
153
|
-
return filtered;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
...config,
|
|
159
|
-
tabBar
|
|
160
|
-
};
|
|
168
|
+
return config;
|
|
161
169
|
}
|
|
162
170
|
function createPagesPlugin(options) {
|
|
163
171
|
const pages = options.pages || {};
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
const MODULE_ID_VIRTUAL = "virtual:univa-pages";
|
|
173
|
+
const RESOLVED_MODULE_ID_VIRTUAL = `\0${MODULE_ID_VIRTUAL}`;
|
|
174
|
+
const virtualData = {
|
|
175
|
+
pages: [],
|
|
176
|
+
subPackages: [],
|
|
177
|
+
tabBar: null
|
|
178
|
+
};
|
|
179
|
+
const virtualModule = () => {
|
|
180
|
+
const pages2 = `export const pages = ${virtualData.pages};`;
|
|
181
|
+
const subPackages = `export const subPackages = ${virtualData.subPackages};`;
|
|
182
|
+
const tabBar = `export const tabBar = ${JSON.stringify(virtualData.tabBar)};`;
|
|
183
|
+
return [pages2, subPackages, tabBar].join("\n");
|
|
184
|
+
};
|
|
185
|
+
const tabbarPlugin = {
|
|
186
|
+
name: "vite-plugin-univa-pages",
|
|
187
|
+
enforce: "pre",
|
|
188
|
+
resolveId(id) {
|
|
189
|
+
if (id === MODULE_ID_VIRTUAL) {
|
|
190
|
+
return RESOLVED_MODULE_ID_VIRTUAL;
|
|
179
191
|
}
|
|
180
192
|
},
|
|
193
|
+
load(id) {
|
|
194
|
+
if (id === RESOLVED_MODULE_ID_VIRTUAL) {
|
|
195
|
+
return virtualModule();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return [
|
|
200
|
+
tabbarPlugin,
|
|
181
201
|
UniHelperPages({
|
|
182
202
|
configSource: pages.config ? {
|
|
183
203
|
files: "vite.config",
|
|
184
204
|
rewrite: () => resolveUserPagesConfig(pages.config)
|
|
185
205
|
} : {
|
|
186
|
-
files: "pages.config"
|
|
187
|
-
extensions: ["ts", "mts", "cts", "js", "cjs", "mjs", "json"]
|
|
206
|
+
files: "pages.config"
|
|
188
207
|
},
|
|
189
208
|
subPackages: [
|
|
190
209
|
...pages.subPackages || []
|
|
@@ -195,29 +214,13 @@ function createPagesPlugin(options) {
|
|
|
195
214
|
],
|
|
196
215
|
onAfterMergePageMetaData(ctx) {
|
|
197
216
|
processPageName(ctx);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const clonedTabBar = { ...tabBar };
|
|
204
|
-
if (clonedTabBar.list) {
|
|
205
|
-
clonedTabBar.list = clonedTabBar.list.map((item) => {
|
|
206
|
-
const filtered = { ...item };
|
|
207
|
-
if (filtered.customIconPath) {
|
|
208
|
-
filtered.iconPath = filtered.customIconPath;
|
|
209
|
-
delete filtered.customIconPath;
|
|
210
|
-
}
|
|
211
|
-
if (filtered.customSelectedIconPath) {
|
|
212
|
-
filtered.selectedIconPath = filtered.customSelectedIconPath;
|
|
213
|
-
delete filtered.customSelectedIconPath;
|
|
214
|
-
}
|
|
215
|
-
return filtered;
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
tabBarConfig = clonedTabBar;
|
|
217
|
+
virtualData.tabBar = processTabBar(ctx);
|
|
218
|
+
},
|
|
219
|
+
onAfterWriteFile(ctx) {
|
|
220
|
+
virtualData.pages = ctx.resolveRoutes();
|
|
221
|
+
virtualData.subPackages = ctx.resolveSubRoutes();
|
|
219
222
|
},
|
|
220
|
-
dts: `${DTS_DIR}/
|
|
223
|
+
dts: `${DTS_DIR}/pages.d.ts`
|
|
221
224
|
})
|
|
222
225
|
];
|
|
223
226
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univa/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验",
|
|
6
6
|
"author": "lianghang <libre1103@163.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"
|
|
8
|
+
"homepage": "mailto:libre1103@163.com",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "mailto:libre1103@163.com"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"uni-app",
|
|
14
|
+
"vite",
|
|
15
|
+
"plugin",
|
|
16
|
+
"unocss",
|
|
17
|
+
"auto-import",
|
|
18
|
+
"components",
|
|
19
|
+
"uni-helper"
|
|
20
|
+
],
|
|
9
21
|
"exports": {
|
|
10
22
|
".": {
|
|
11
23
|
"import": {
|
|
@@ -41,6 +53,9 @@
|
|
|
41
53
|
"src/client.d.ts",
|
|
42
54
|
"src/global.d.ts"
|
|
43
55
|
],
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=20.0.0"
|
|
58
|
+
},
|
|
44
59
|
"publishConfig": {
|
|
45
60
|
"access": "public",
|
|
46
61
|
"registry": "https://registry.npmjs.org/"
|
package/src/client.d.ts
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
/// <reference types="@uni-ku/bundle-optimizer/client" />
|
|
5
5
|
/// <reference types="@uni-helper/uni-types" />
|
|
6
6
|
|
|
7
|
-
declare module 'virtual:univa-
|
|
8
|
-
import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
|
|
7
|
+
declare module 'virtual:univa-pages' {
|
|
8
|
+
import type { PageMetaDatum, SubPackage, TabBar } from '@uni-helper/vite-plugin-uni-pages'
|
|
9
9
|
|
|
10
|
-
const tabBar: TabBar
|
|
11
|
-
export
|
|
10
|
+
export const tabBar: TabBar
|
|
11
|
+
export const pages: PageMetaDatum[]
|
|
12
|
+
export const subPackages: SubPackage[]
|
|
12
13
|
}
|