@univa/core 0.0.4 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lianghang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  > 🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验
4
4
 
5
+ [![npm](https://img.shields.io/npm/v/@univa/core)](https://www.npmjs.com/package/@univa/core)
6
+ [![downloads](https://img.shields.io/npm/dm/@univa/core)](https://www.npmjs.com/package/@univa/core)
7
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@univa/core)](https://bundlephobia.com/package/@univa/core)
8
+ [![license](https://img.shields.io/badge/license-MIT-blue)](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
- #### 获取 TabBar 配置
165
+ #### 获取 Pages 配置
158
166
 
159
- 在组件中获取 tabBar 配置:
167
+ 在组件中获取 Pages 配置:
160
168
 
161
169
  ```typescript
162
- import tabBar from 'virtual:univa-tabbar'
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
- ```typescript
180
- 'border-s' // border border-solid
181
- 'wh-full' // w-full h-full
182
- 'f-c-c' // flex justify-center items-center
183
- 'f-col-c' // flex-col justify-center items-center
184
- 'flex-items' // flex items-center
185
- 'flex-justify' // flex justify-center
186
- 'flex-col' // flex flex-col
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
@@ -30,8 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- COMPONENT_ASYNC_ROOT: () => COMPONENT_ASYNC_ROOT,
34
- DTS_DIR: () => DTS_DIR,
35
33
  Univa: () => Univa,
36
34
  definePagesConfig: () => definePagesConfig,
37
35
  presetUniva: () => presetUniva
@@ -172,59 +170,78 @@ function processPageName(ctx) {
172
170
  });
173
171
  });
174
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
+ }
175
202
  function resolveUserPagesConfig(config) {
176
203
  if (!config.tabBar) {
177
204
  return config;
178
205
  }
179
- const tabBar = config.tabBar || {};
180
- if (config.tabBarMode === "CUSTOM") {
181
- tabBar.custom = true;
182
- if (tabBar.list && tabBar.list.length > 0) {
183
- tabBar.list = tabBar.list.map((item) => {
184
- const filtered = { ...item };
185
- filtered.customIconPath = filtered.iconPath;
186
- filtered.customSelectedIconPath = filtered.selectedIconPath;
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
- }
197
- return {
198
- ...config,
199
- tabBar
200
- };
206
+ return config;
201
207
  }
202
208
  function createPagesPlugin(options) {
203
209
  const pages = options.pages || {};
204
- let tabBarConfig = null;
205
- const moduleId = "\0virtual:univa-tabbar";
206
- return [
207
- {
208
- name: "vite-plugin-univa-pages-tabbar",
209
- enforce: "pre",
210
- resolveId(id) {
211
- if (id === "virtual:univa-tabbar") {
212
- return moduleId;
213
- }
214
- },
215
- load(id) {
216
- if (id === moduleId) {
217
- return `export default ${JSON.stringify(tabBarConfig)}`;
218
- }
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;
219
229
  }
220
230
  },
231
+ load(id) {
232
+ if (id === RESOLVED_MODULE_ID_VIRTUAL) {
233
+ return virtualModule();
234
+ }
235
+ }
236
+ };
237
+ return [
238
+ tabbarPlugin,
221
239
  (0, import_vite_plugin_uni_pages.default)({
222
240
  configSource: pages.config ? {
223
241
  files: "vite.config",
224
242
  rewrite: () => resolveUserPagesConfig(pages.config)
225
243
  } : {
226
- files: "pages.config",
227
- extensions: ["ts", "mts", "cts", "js", "cjs", "mjs", "json"]
244
+ files: "pages.config"
228
245
  },
229
246
  subPackages: [
230
247
  ...pages.subPackages || []
@@ -235,29 +252,13 @@ function createPagesPlugin(options) {
235
252
  ],
236
253
  onAfterMergePageMetaData(ctx) {
237
254
  processPageName(ctx);
238
- const tabBar = ctx.pagesGlobConfig?.tabBar;
239
- if (!tabBar) {
240
- tabBarConfig = null;
241
- return;
242
- }
243
- const clonedTabBar = { ...tabBar };
244
- if (clonedTabBar.list) {
245
- clonedTabBar.list = clonedTabBar.list.map((item) => {
246
- const filtered = { ...item };
247
- if (filtered.customIconPath) {
248
- filtered.iconPath = filtered.customIconPath;
249
- delete filtered.customIconPath;
250
- }
251
- if (filtered.customSelectedIconPath) {
252
- filtered.selectedIconPath = filtered.customSelectedIconPath;
253
- delete filtered.customSelectedIconPath;
254
- }
255
- return filtered;
256
- });
257
- }
258
- tabBarConfig = clonedTabBar;
255
+ virtualData.tabBar = processTabBar(ctx);
256
+ },
257
+ onAfterWriteFile(ctx) {
258
+ virtualData.pages = ctx.resolveRoutes();
259
+ virtualData.subPackages = ctx.resolveSubRoutes();
259
260
  },
260
- dts: `${DTS_DIR}/uni-pages.d.ts`
261
+ dts: `${DTS_DIR}/pages.d.ts`
261
262
  })
262
263
  ];
263
264
  }
@@ -368,8 +369,6 @@ function Univa(config) {
368
369
  }
369
370
  // Annotate the CommonJS export names for ESM import in node:
370
371
  0 && (module.exports = {
371
- COMPONENT_ASYNC_ROOT,
372
- DTS_DIR,
373
372
  Univa,
374
373
  definePagesConfig,
375
374
  presetUniva
package/dist/index.d.cts CHANGED
@@ -35,9 +35,6 @@ declare function definePagesConfig(config: DefinePagesConfig): DefinePagesConfig
35
35
 
36
36
  declare function presetUniva(): Preset;
37
37
 
38
- declare const DTS_DIR = "./.univa";
39
- declare const COMPONENT_ASYNC_ROOT = "components-async";
40
-
41
38
  declare function Univa(config?: UnivaUserConfig): PluginOption[];
42
39
 
43
- export { COMPONENT_ASYNC_ROOT, DTS_DIR, Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
40
+ export { Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
package/dist/index.d.ts CHANGED
@@ -35,9 +35,6 @@ declare function definePagesConfig(config: DefinePagesConfig): DefinePagesConfig
35
35
 
36
36
  declare function presetUniva(): Preset;
37
37
 
38
- declare const DTS_DIR = "./.univa";
39
- declare const COMPONENT_ASYNC_ROOT = "components-async";
40
-
41
38
  declare function Univa(config?: UnivaUserConfig): PluginOption[];
42
39
 
43
- export { COMPONENT_ASYNC_ROOT, DTS_DIR, Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
40
+ export { Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
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
- const tabBar = config.tabBar || {};
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
- let tabBarConfig = null;
165
- const moduleId = "\0virtual:univa-tabbar";
166
- return [
167
- {
168
- name: "vite-plugin-univa-pages-tabbar",
169
- enforce: "pre",
170
- resolveId(id) {
171
- if (id === "virtual:univa-tabbar") {
172
- return moduleId;
173
- }
174
- },
175
- load(id) {
176
- if (id === moduleId) {
177
- return `export default ${JSON.stringify(tabBarConfig)}`;
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
- const tabBar = ctx.pagesGlobConfig?.tabBar;
199
- if (!tabBar) {
200
- tabBarConfig = null;
201
- return;
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}/uni-pages.d.ts`
223
+ dts: `${DTS_DIR}/pages.d.ts`
221
224
  })
222
225
  ];
223
226
  }
@@ -327,8 +330,6 @@ function Univa(config) {
327
330
  });
328
331
  }
329
332
  export {
330
- COMPONENT_ASYNC_ROOT,
331
- DTS_DIR,
332
333
  Univa,
333
334
  definePagesConfig,
334
335
  presetUniva
package/package.json CHANGED
@@ -1,11 +1,23 @@
1
1
  {
2
2
  "name": "@univa/core",
3
3
  "type": "module",
4
- "version": "0.0.4",
5
- "description": "",
6
- "author": "",
4
+ "version": "0.0.6",
5
+ "description": "🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验",
6
+ "author": "lianghang <libre1103@163.com>",
7
7
  "license": "MIT",
8
- "keywords": [],
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": {
@@ -35,11 +47,15 @@
35
47
  "module": "./dist/index.js",
36
48
  "types": "./dist/index.d.ts",
37
49
  "files": [
50
+ "LICENSE",
38
51
  "README.md",
39
52
  "dist",
40
53
  "src/client.d.ts",
41
54
  "src/global.d.ts"
42
55
  ],
56
+ "engines": {
57
+ "node": ">=20.0.0"
58
+ },
43
59
  "publishConfig": {
44
60
  "access": "public",
45
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-tabbar' {
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 default tabBar
10
+ export const tabBar: TabBar
11
+ export const pages: PageMetaDatum[]
12
+ export const subPackages: SubPackage[]
12
13
  }