@univa/core 0.0.6 → 0.0.7

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/dist/index.js CHANGED
@@ -1,336 +1,359 @@
1
+ // src/config/index.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
1
6
  // src/plugins/index.ts
2
7
  import Uni from "@uni-helper/plugin-uni";
3
- import UniHelperLayouts from "@uni-helper/vite-plugin-uni-layouts";
4
- import UniOptimization from "@uni-ku/bundle-optimizer";
5
- import UnivaRoot from "@univa/root";
6
- import UniPolyfill from "vite-plugin-uni-polyfill";
8
+ import VitePluginUniComponents from "@uni-helper/vite-plugin-uni-components";
9
+ import { VitePluginUniLayouts } from "@uni-helper/vite-plugin-uni-layouts";
10
+ import UniKuRoot from "@uni-ku/root";
11
+ import UnoCSS from "unocss/vite";
12
+ import AutoImport from "unplugin-auto-import/vite";
7
13
 
8
14
  // src/constant.ts
9
- var DTS_DIR = "./.univa";
10
- var COMPONENT_ASYNC_ROOT = "components-async";
15
+ var ID = "univa";
16
+ var UNIVA_DIR_NAME = `.${ID}`;
11
17
 
12
- // src/plugins/autoImport.ts
13
- import AutoImport from "unplugin-auto-import/vite";
14
- function createAutoImportPlugin(options) {
15
- const defaultAutoImportOptions = {
16
- imports: [
17
- "vue",
18
- "pinia",
19
- "uni-app",
20
- {
21
- from: "@univa/core/hooks",
22
- imports: ["usePageContext"]
23
- }
24
- ],
25
- dirs: [
26
- "src/hooks/**",
27
- "!src/hooks/**/_*/**",
28
- "src/store/**",
29
- "!src/store/**/_*/**",
30
- "src/constants/**"
31
- ],
32
- vueTemplate: true,
33
- dts: `${DTS_DIR}/auto-imports.d.ts`
34
- };
35
- const userAutoImportOptions = typeof options.autoImport === "object" ? options.autoImport : {};
36
- const mergedOptions = {
37
- ...defaultAutoImportOptions,
38
- ...userAutoImportOptions
39
- };
40
- if (userAutoImportOptions.imports) {
41
- const userImports = Array.isArray(userAutoImportOptions.imports) ? userAutoImportOptions.imports : [userAutoImportOptions.imports];
42
- mergedOptions.imports = [...defaultAutoImportOptions.imports, ...userImports];
43
- }
44
- if (userAutoImportOptions.dirs) {
45
- const userDirs = Array.isArray(userAutoImportOptions.dirs) ? userAutoImportOptions.dirs : [userAutoImportOptions.dirs];
46
- mergedOptions.dirs = [...defaultAutoImportOptions.dirs, ...userDirs];
18
+ // src/utils/fs.ts
19
+ import { existsSync, mkdirSync } from "fs";
20
+ import { join } from "path";
21
+ function ensureDir(dir) {
22
+ if (!existsSync(dir)) {
23
+ mkdirSync(dir, { recursive: true });
47
24
  }
48
- return AutoImport(mergedOptions);
25
+ }
26
+ function getUnivaDir(cwd) {
27
+ return join(cwd, UNIVA_DIR_NAME);
28
+ }
29
+ function ensureUnivaDir(cwd) {
30
+ const dir = getUnivaDir(cwd);
31
+ ensureDir(dir);
32
+ return dir;
49
33
  }
50
34
 
51
- // src/plugins/components.ts
52
- import UniHelperComponents from "@uni-helper/vite-plugin-uni-components";
53
- function createComponentsPlugin(options) {
54
- const defaultComponentsOptions = {
55
- dirs: ["src/components", "src/components-biz"],
56
- exclude: ["**/components/**/*.*"],
57
- directoryAsNamespace: true,
58
- globalNamespaces: ["components", "common"],
59
- dts: `${DTS_DIR}/components.d.ts`
60
- };
61
- const userComponentsOptions = typeof options.components === "object" ? options.components : {};
62
- const mergedOptions = {
63
- ...defaultComponentsOptions,
64
- ...userComponentsOptions
65
- };
66
- if (userComponentsOptions.dirs) {
67
- const userDirs = Array.isArray(userComponentsOptions.dirs) ? userComponentsOptions.dirs : [userComponentsOptions.dirs];
68
- mergedOptions.dirs = [...defaultComponentsOptions.dirs, ...userDirs];
69
- }
70
- if (userComponentsOptions.exclude) {
71
- const userExclude = Array.isArray(userComponentsOptions.exclude) ? userComponentsOptions.exclude : [userComponentsOptions.exclude];
72
- mergedOptions.exclude = [...defaultComponentsOptions.exclude, ...userExclude];
73
- }
74
- if (userComponentsOptions.globalNamespaces) {
75
- const userGlobalNamespaces = Array.isArray(userComponentsOptions.globalNamespaces) ? userComponentsOptions.globalNamespaces : [userComponentsOptions.globalNamespaces];
76
- mergedOptions.globalNamespaces = [...defaultComponentsOptions.globalNamespaces, ...userGlobalNamespaces];
35
+ // src/plugins/context.ts
36
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
37
+ import { join as join3 } from "path";
38
+ import { slash } from "@antfu/utils";
39
+ import { loadConfig } from "c12";
40
+ import { createJiti } from "jiti";
41
+
42
+ // src/utils/merge.ts
43
+ import { createDefu } from "defu";
44
+ var mergeWithArrayOverride = createDefu((originObj, key, updates) => {
45
+ if (Array.isArray(originObj[key]) && Array.isArray(updates)) {
46
+ originObj[key] = updates;
47
+ return true;
77
48
  }
78
- return UniHelperComponents(mergedOptions);
79
- }
49
+ });
80
50
 
81
- // src/plugins/manifest.ts
82
- import { VitePluginUniManifest } from "@univa/manifest";
83
- function createManifestPlugin(options) {
84
- return VitePluginUniManifest({
85
- rewrite: (config) => {
86
- return options?.manifest || config;
51
+ // src/plugins/pages.ts
52
+ import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
53
+ import { join as join2 } from "path";
54
+ import { VitePluginUniPages } from "@uni-helper/vite-plugin-uni-pages";
55
+ function getPagesConfigPath(root) {
56
+ return join2(getUnivaDir(root), "pages-config.ts");
57
+ }
58
+ function generatePagesConfigContent(content) {
59
+ const { pages, subPackages, ...rest } = content;
60
+ void pages;
61
+ void subPackages;
62
+ return `// Auto-generated by @univa/core
63
+ // \u6765\u6E90\uFF1Auniva.config.ts \u7684 pages \u5B57\u6BB5
64
+ export default ${JSON.stringify(rest, null, 2)}
65
+ `;
66
+ }
67
+ function generatePagesConfigFile(content, root) {
68
+ const pagesConfigPath = getPagesConfigPath(root);
69
+ const newContent = generatePagesConfigContent(content);
70
+ if (existsSync2(pagesConfigPath)) {
71
+ const existingContent = readFileSync(pagesConfigPath, "utf-8");
72
+ if (existingContent === newContent) {
73
+ return;
87
74
  }
75
+ }
76
+ writeFileSync(pagesConfigPath, newContent, "utf-8");
77
+ }
78
+ function createPagesPlugin(pluginOptions) {
79
+ const result = VitePluginUniPages({
80
+ dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
81
+ exclude: ["**/components/**/*.*"],
82
+ configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
83
+ ...pluginOptions
88
84
  });
85
+ return Array.isArray(result) ? result : [result];
89
86
  }
90
87
 
91
- // src/plugins/pages.ts
92
- import UniHelperPages from "@uni-helper/vite-plugin-uni-pages";
93
- function _pathToName(path, partToReplace = "", prefix = "") {
94
- const parts = path.replace(/\.\w+$/, "").split("/").filter(Boolean);
95
- const toPascalCase = (parts2) => {
96
- return parts2.map(
97
- (part) => part.split("-").map((subPart) => subPart.charAt(0).toUpperCase() + subPart.slice(1)).join("")
98
- ).join("");
99
- };
100
- if (!partToReplace) {
101
- return toPascalCase(parts);
102
- }
103
- const indexToReplace = parts.findIndex((part) => part.toLowerCase() === partToReplace.toLowerCase());
104
- if (indexToReplace === -1) {
105
- return prefix + toPascalCase(parts);
88
+ // src/plugins/context.ts
89
+ var DEFAULT_ROOT_FILE_NAME = "App.ku.vue";
90
+ var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
91
+ <!-- UniKuRoot \u865A\u62DF\u6839\u7EC4\u4EF6\uFF0C\u53EF\u5728\u6B64\u6DFB\u52A0\u5168\u5C40\u7EC4\u4EF6\uFF08\u5982 Toast\u3001ConfigProvider \u7B49\uFF09 -->
92
+ <template>
93
+ <KuRootView />
94
+ </template>
95
+ `;
96
+ function ensureRootComponent(config, root) {
97
+ const srcDir = config?.srcDir || "src";
98
+ const rootFileName = config?.overrides?.root?.rootFileName || DEFAULT_ROOT_FILE_NAME;
99
+ const rootComponentPath = join3(root, srcDir, rootFileName);
100
+ if (existsSync3(rootComponentPath)) {
101
+ return;
106
102
  }
107
- parts[indexToReplace] = prefix;
108
- return toPascalCase(parts);
103
+ writeFileSync2(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
104
+ console.log(`[univa] \u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${slash(rootComponentPath)}`);
109
105
  }
110
- function processPageName(ctx) {
111
- ctx.pageMetaData.forEach((page) => {
112
- if (page.name) {
106
+ var UnivaContext = class {
107
+ _server;
108
+ config;
109
+ configPath;
110
+ root;
111
+ constructor(options) {
112
+ this.root = options.root;
113
+ }
114
+ /**
115
+ * 同步加载用户配置(univa.config.ts)
116
+ */
117
+ loadUserConfigSync() {
118
+ const jiti = createJiti(this.root);
119
+ const configFile = join3(this.root, `${ID}.config`);
120
+ try {
121
+ const configModule = jiti(configFile);
122
+ const userConfig = configModule?.default || configModule;
123
+ this.config = mergeWithArrayOverride({}, userConfig);
124
+ this.configPath = jiti.resolve(configFile);
125
+ } catch {
126
+ }
127
+ }
128
+ /**
129
+ * 异步加载用户配置(c12 支持更多格式与合并能力)
130
+ */
131
+ async loadUserConfigAsync() {
132
+ const { config: userConfig, configFile } = await loadConfig({
133
+ name: ID,
134
+ cwd: this.root,
135
+ defaults: this.config || {},
136
+ merger: mergeWithArrayOverride
137
+ });
138
+ this.config = userConfig;
139
+ this.configPath = configFile || "";
140
+ }
141
+ /**
142
+ * 设置 Vite 开发服务器
143
+ */
144
+ setupViteServer(server) {
145
+ if (this._server === server)
146
+ return;
147
+ this._server = server;
148
+ this.setupWatcher(server.watcher);
149
+ }
150
+ /**
151
+ * 设置文件监听器
152
+ *
153
+ * 监听 univa.config.ts 变化,重新生成 .univa/pages.ts
154
+ */
155
+ setupWatcher(watcher) {
156
+ if (!this.configPath) {
113
157
  return;
114
158
  }
115
- page.name = _pathToName(page.path, "pages");
116
- });
117
- ctx.subPageMetaData.forEach((subPackage) => {
118
- const root = subPackage.root;
119
- const isAsyncComponent = root.startsWith(COMPONENT_ASYNC_ROOT);
120
- subPackage.pages.forEach((page) => {
121
- if (page.name) {
159
+ watcher.add(this.configPath);
160
+ watcher.on("change", async (filePath) => {
161
+ filePath = slash(filePath);
162
+ const configPath = slash(this.configPath || "");
163
+ if (filePath !== configPath) {
122
164
  return;
123
165
  }
124
- if (!page.path) {
125
- console.warn(`[vite-plugin-uni-pages] Page path is missing in subPackage: ${root}`);
126
- return;
127
- }
128
- if (isAsyncComponent) {
129
- page.layout = false;
130
- }
131
- page.name = _pathToName(`${root}/${page.path}`, "pages-sub", "Sub");
166
+ await this.updateConfig();
167
+ this.onUpdate();
132
168
  });
133
- });
134
- }
135
- function processTabBar(ctx) {
136
- const tabBar = ctx.pagesGlobConfig?.tabBar;
137
- if (!tabBar) {
138
- return;
139
169
  }
140
- const tabBarMode = ctx.pagesGlobConfig?.tabBarMode || "NATIVE";
141
- if (tabBarMode === "CUSTOM") {
142
- tabBar.custom = true;
170
+ async updateConfig() {
171
+ await this.loadUserConfigAsync();
172
+ this.updateGeneratedFiles();
143
173
  }
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;
174
+ /**
175
+ * 更新生成的文件
176
+ *
177
+ * 读取 univa.config.ts pages 字段(应用级配置),
178
+ * 生成 .univa/pages.ts VitePluginUniPages 消费。
179
+ * 同时确保 UniKuRoot 虚拟根组件文件存在。
180
+ */
181
+ updateGeneratedFiles() {
182
+ const pagesConfig = this.config?.pages;
183
+ if (pagesConfig) {
184
+ generatePagesConfigFile(pagesConfig, this.root);
185
+ }
186
+ const pagesTsPath = getPagesConfigPath(this.root);
187
+ const emptyContent = `// Auto-generated by @univa/core
188
+ export default {}
189
+ `;
190
+ if (!existsSync3(pagesTsPath)) {
191
+ writeFileSync2(pagesTsPath, emptyContent, "utf-8");
192
+ } else if (!pagesConfig) {
193
+ if (readFileSync2(pagesTsPath, "utf-8") !== emptyContent) {
194
+ writeFileSync2(pagesTsPath, emptyContent, "utf-8");
154
195
  }
155
- return filtered;
156
- });
157
- }
158
- const clonedTabBar = { ...tabBar };
159
- if (clonedTabBar.list) {
160
- clonedTabBar.list = rawTabBarList;
196
+ }
197
+ ensureRootComponent(this.config, this.root);
161
198
  }
162
- return clonedTabBar;
163
- }
164
- function resolveUserPagesConfig(config) {
165
- if (!config.tabBar) {
166
- return config;
199
+ /**
200
+ * 更新回调
201
+ * 触发 HMR
202
+ */
203
+ onUpdate() {
204
+ if (!this._server) {
205
+ return;
206
+ }
207
+ this._server.ws.send({
208
+ type: "full-reload"
209
+ });
167
210
  }
168
- return config;
169
- }
170
- function createPagesPlugin(options) {
171
- const pages = options.pages || {};
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");
211
+ };
212
+
213
+ // src/plugins/options.ts
214
+ var DEFAULT_DIRS = {
215
+ pages: "pages",
216
+ subPackages: ["pages-sub/*"],
217
+ layouts: "layouts"
218
+ };
219
+ var DEFAULT_IMPORTS = {
220
+ apis: ["vue", "uni-app", "composables/**", "stores/**", "hooks/**", "constants/**"],
221
+ components: ["components/**", "components-biz/**"]
222
+ };
223
+ function resolveOptions(userOptions) {
224
+ const srcDir = userOptions.srcDir || "src";
225
+ const dirs = {
226
+ pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
227
+ subPackages: userOptions.dirs?.subPackages ?? DEFAULT_DIRS.subPackages,
228
+ layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
184
229
  };
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;
191
- }
192
- },
193
- load(id) {
194
- if (id === RESOLVED_MODULE_ID_VIRTUAL) {
195
- return virtualModule();
196
- }
197
- }
230
+ const imports = {
231
+ apis: userOptions.imports?.apis ?? DEFAULT_IMPORTS.apis,
232
+ components: userOptions.imports?.components ?? DEFAULT_IMPORTS.components
198
233
  };
199
- return [
200
- tabbarPlugin,
201
- UniHelperPages({
202
- configSource: pages.config ? {
203
- files: "vite.config",
204
- rewrite: () => resolveUserPagesConfig(pages.config)
205
- } : {
206
- files: "pages.config"
207
- },
208
- subPackages: [
209
- ...pages.subPackages || []
210
- ],
211
- exclude: [
212
- ...pages?.exclude || [],
213
- "**/components/**/*.*"
214
- ],
215
- onAfterMergePageMetaData(ctx) {
216
- processPageName(ctx);
217
- virtualData.tabBar = processTabBar(ctx);
218
- },
219
- onAfterWriteFile(ctx) {
220
- virtualData.pages = ctx.resolveRoutes();
221
- virtualData.subPackages = ctx.resolveSubRoutes();
222
- },
223
- dts: `${DTS_DIR}/pages.d.ts`
224
- })
225
- ];
226
- }
227
- function definePagesConfig(config) {
228
- return config;
229
- }
230
-
231
- // src/plugins/unocss.ts
232
- import { presetUni } from "@uni-helper/unocss-preset-uni";
233
- import presetLegacyCompat from "@unocss/preset-legacy-compat";
234
- import { presetIcons, transformerDirectives, transformerVariantGroup } from "unocss";
235
- import UnoCSS from "unocss/vite";
236
- function createUnocssPlugin() {
237
- return UnoCSS({
238
- presets: [
239
- presetUniva()
240
- ]
241
- });
242
- }
243
- function presetUniva() {
244
234
  return {
245
- name: "univa-preset",
246
- presets: [
247
- presetUni({
248
- attributify: false
249
- }),
250
- presetIcons({
251
- scale: 1.2,
252
- warn: true,
253
- extraProperties: {
254
- "display": "inline-block",
255
- "vertical-align": "middle"
256
- }
257
- }),
258
- // 处理低端安卓机的样式问题,eg: `rgb(255 0 0)` -> `rgb(255, 0, 0)`
259
- presetLegacyCompat({
260
- commaStyleColorFunction: true,
261
- legacyColorSpace: true
262
- })
263
- ],
264
- shortcuts: [
265
- ["border-s", "border border-solid"],
266
- ["wh-full", "w-full h-full"],
267
- ["f-c-c", "flex justify-center items-center"],
268
- ["f-col-c", "flex-col justify-center items-center"],
269
- ["flex-items", "flex items-center"],
270
- ["flex-justify", "flex justify-center"],
271
- ["flex-col", "flex flex-col"]
272
- ],
273
- transformers: [
274
- transformerDirectives(),
275
- transformerVariantGroup()
276
- ],
277
- rules: [
278
- [
279
- "p-safe",
280
- {
281
- padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
282
- }
283
- ],
284
- ["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
285
- ["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
286
- ]
235
+ srcDir,
236
+ dirs,
237
+ imports,
238
+ overrides: userOptions.overrides
287
239
  };
288
240
  }
289
241
 
290
242
  // src/plugins/index.ts
291
- function createUnivaPlugins(options) {
292
- const pluginFactory = {
293
- plugins: [
294
- ...createPagesPlugin(options),
295
- UniHelperLayouts()
296
- ],
297
- register(condition, plugin) {
298
- if (condition) {
299
- this.plugins.push(plugin);
300
- }
243
+ var context;
244
+ function createCorePlugin() {
245
+ return {
246
+ name: "vite-plugin-univa",
247
+ enforce: "pre",
248
+ async configResolved() {
249
+ await context.loadUserConfigAsync();
250
+ context.updateGeneratedFiles();
251
+ },
252
+ configureServer(server) {
253
+ context.setupViteServer(server);
301
254
  }
302
255
  };
303
- pluginFactory.register(options.appRoot !== false, UnivaRoot({
304
- enabledVirtualHost: true,
305
- rootFileName: "App.univa",
256
+ }
257
+ function isPresetName(from) {
258
+ if (/[*?[\]{}]/.test(from))
259
+ return false;
260
+ if (/^@[\w.-]+\/[\w.-]+$/.test(from))
261
+ return true;
262
+ if (/[/\\]/.test(from))
263
+ return false;
264
+ return true;
265
+ }
266
+ function resolveApiSources(sources, srcDir) {
267
+ const presets = [];
268
+ const dirs = [];
269
+ for (const source of sources) {
270
+ if (typeof source !== "string") {
271
+ presets.push(source);
272
+ } else if (source.startsWith("!")) {
273
+ dirs.push(`!${srcDir}/${source.slice(1)}`);
274
+ } else if (isPresetName(source)) {
275
+ presets.push(source);
276
+ } else {
277
+ dirs.push(`${srcDir}/${source}`);
278
+ }
279
+ }
280
+ return { presets, dirs };
281
+ }
282
+ function createUnivaPlugins(resolved) {
283
+ const plugins = [];
284
+ const { srcDir } = resolved;
285
+ plugins.push(createCorePlugin());
286
+ plugins.push(...createPagesPlugin({
287
+ dir: `${srcDir}/${resolved.dirs.pages}`,
288
+ subPackages: resolved.dirs.subPackages.map((p) => `${srcDir}/${p}`),
289
+ ...resolved.overrides?.pages
290
+ }));
291
+ plugins.push(VitePluginUniLayouts({
292
+ layoutDir: `${srcDir}/${resolved.dirs.layouts}`,
293
+ ...resolved.overrides?.layouts
294
+ }));
295
+ plugins.push(UniKuRoot({
306
296
  enabledGlobalRef: true,
307
- autoCreateRoot: true,
308
297
  excludePages: [
309
- `${COMPONENT_ASYNC_ROOT}/**/*.*`
310
- ]
298
+ "components-async/**/*.*"
299
+ ],
300
+ ...resolved.overrides?.root
301
+ }));
302
+ plugins.push(VitePluginUniComponents({
303
+ dirs: resolved.imports.components.map((c) => `${srcDir}/${c}`),
304
+ dts: `${UNIVA_DIR_NAME}/components.d.ts`,
305
+ globalNamespaces: ["components", "common"],
306
+ directoryAsNamespace: true,
307
+ ...resolved.overrides?.components
311
308
  }));
312
- pluginFactory.register(true, createManifestPlugin(options));
313
- pluginFactory.register(options.components !== false, createComponentsPlugin(options));
314
- pluginFactory.register(true, UniOptimization());
315
- pluginFactory.register(true, Uni());
316
- pluginFactory.register(true, createUnocssPlugin());
317
- pluginFactory.register(options.autoImport !== false, createAutoImportPlugin(options));
318
- pluginFactory.register(true, UniPolyfill());
319
- return pluginFactory.plugins;
309
+ plugins.push(...Uni());
310
+ plugins.push(...UnoCSS());
311
+ const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
312
+ const autoImportPlugin = AutoImport({
313
+ imports: presets,
314
+ dirs,
315
+ dts: `${UNIVA_DIR_NAME}/auto-imports.d.ts`,
316
+ ...resolved.overrides?.autoImport
317
+ });
318
+ if (Array.isArray(autoImportPlugin)) {
319
+ plugins.push(...autoImportPlugin);
320
+ } else {
321
+ plugins.push(autoImportPlugin);
322
+ }
323
+ return plugins;
320
324
  }
321
-
322
- // src/index.ts
323
- function Univa(config) {
324
- return createUnivaPlugins({
325
- components: config?.components ?? true,
326
- autoImport: config?.autoImport ?? true,
327
- appRoot: config?.appRoot ?? true,
328
- pages: config?.pages,
329
- manifest: config?.manifest
325
+ function Univa() {
326
+ context = new UnivaContext({
327
+ root: process.cwd()
330
328
  });
329
+ ensureUnivaDir(context.root);
330
+ context.loadUserConfigSync();
331
+ const resolved = resolveOptions(context.config || {});
332
+ console.log("[univa] \u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
333
+ return createUnivaPlugins(resolved);
331
334
  }
335
+ var plugins_default = Univa;
336
+
337
+ // src/index.ts
338
+ import { presetUni } from "@uni-helper/unocss-preset-uni";
339
+ import { camelCase, kebabCase, pascalCase } from "@uni-helper/vite-plugin-uni-components";
340
+ import { default as default2 } from "@uni-helper/vite-plugin-uni-components";
341
+ import { VitePluginUniLayouts as VitePluginUniLayouts2 } from "@uni-helper/vite-plugin-uni-layouts";
342
+ import { PageContext, VitePluginUniPages as VitePluginUniPages2 } from "@uni-helper/vite-plugin-uni-pages";
343
+ import { default as default3 } from "@uni-ku/root";
344
+ import { default as default4 } from "unplugin-auto-import/vite";
332
345
  export {
333
- Univa,
334
- definePagesConfig,
335
- presetUniva
346
+ default4 as AutoImport,
347
+ PageContext,
348
+ default3 as UniKuRoot,
349
+ plugins_default as Univa,
350
+ default2 as VitePluginUniComponents,
351
+ VitePluginUniLayouts2 as VitePluginUniLayouts,
352
+ VitePluginUniPages2 as VitePluginUniPages,
353
+ camelCase,
354
+ createUnivaPlugins,
355
+ defineConfig,
356
+ kebabCase,
357
+ pascalCase,
358
+ presetUni
336
359
  };