@univa/core 0.0.9 → 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/dist/global.d.ts +1 -0
- package/dist/index.cjs +324 -144
- package/dist/index.d.cts +29 -7
- package/dist/index.d.ts +29 -7
- package/dist/index.js +321 -140
- package/package.json +2 -1
package/dist/global.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AutoImport: () => import_vite4.default,
|
|
34
|
-
|
|
35
|
-
UniKuRoot: () => import_root2.default,
|
|
34
|
+
UniKuRoot: () => import_root3.default,
|
|
36
35
|
Univa: () => plugins_default,
|
|
37
36
|
VitePluginUniComponents: () => import_vite_plugin_uni_components3.default,
|
|
38
37
|
VitePluginUniLayouts: () => import_vite_plugin_uni_layouts2.VitePluginUniLayouts,
|
|
@@ -42,7 +41,7 @@ __export(index_exports, {
|
|
|
42
41
|
defineConfig: () => defineConfig,
|
|
43
42
|
kebabCase: () => import_vite_plugin_uni_components2.kebabCase,
|
|
44
43
|
pascalCase: () => import_vite_plugin_uni_components2.pascalCase,
|
|
45
|
-
presetUni: () =>
|
|
44
|
+
presetUni: () => import_unocss_preset_uni2.presetUni
|
|
46
45
|
});
|
|
47
46
|
module.exports = __toCommonJS(index_exports);
|
|
48
47
|
|
|
@@ -55,14 +54,17 @@ function defineConfig(config) {
|
|
|
55
54
|
var import_plugin_uni = __toESM(require("@uni-helper/plugin-uni"), 1);
|
|
56
55
|
var import_vite_plugin_uni_components = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
|
|
57
56
|
var import_vite_plugin_uni_layouts = require("@uni-helper/vite-plugin-uni-layouts");
|
|
58
|
-
var
|
|
59
|
-
var import_vite2 = __toESM(require("unocss/vite"), 1);
|
|
57
|
+
var import_bundle_optimizer = __toESM(require("@uni-ku/bundle-optimizer"), 1);
|
|
60
58
|
var import_vite3 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
59
|
+
var import_vite_plugin_uni_polyfill = __toESM(require("vite-plugin-uni-polyfill"), 1);
|
|
61
60
|
|
|
62
61
|
// src/constant.ts
|
|
63
62
|
var ID = "univa";
|
|
64
63
|
var UNIVA_DIR_NAME = `.${ID}`;
|
|
65
64
|
var ROOT_NAME = `${ID}.root`;
|
|
65
|
+
var COMPONENTS_ASYNC_DIR_NAME = "components-async";
|
|
66
|
+
var SUB_PACKAGE_DIR_NAME = "app";
|
|
67
|
+
var PAGES_JSON_FILE_NAME = "pages.json";
|
|
66
68
|
|
|
67
69
|
// src/utils/fs.ts
|
|
68
70
|
var import_node_fs = require("fs");
|
|
@@ -80,6 +82,21 @@ function ensureUnivaDir(cwd) {
|
|
|
80
82
|
ensureDir(dir);
|
|
81
83
|
return dir;
|
|
82
84
|
}
|
|
85
|
+
function getSubDirectories(dirPath) {
|
|
86
|
+
if (!(0, import_node_fs.existsSync)(dirPath)) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const entries = (0, import_node_fs.readdirSync)(dirPath);
|
|
90
|
+
return entries.filter((entry) => {
|
|
91
|
+
const fullPath = (0, import_node_path.join)(dirPath, entry);
|
|
92
|
+
return (0, import_node_fs.statSync)(fullPath).isDirectory();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function scanSubPackages(srcDir, subPackageRoot) {
|
|
96
|
+
const rootPath = (0, import_node_path.join)(srcDir, subPackageRoot);
|
|
97
|
+
const subDirs = getSubDirectories(rootPath);
|
|
98
|
+
return subDirs.map((name) => import_node_path.posix.join(subPackageRoot, name));
|
|
99
|
+
}
|
|
83
100
|
|
|
84
101
|
// src/utils/logger.ts
|
|
85
102
|
var debugMode = false;
|
|
@@ -93,8 +110,7 @@ function log(message, ...args) {
|
|
|
93
110
|
}
|
|
94
111
|
|
|
95
112
|
// src/plugins/context.ts
|
|
96
|
-
var
|
|
97
|
-
var import_node_path4 = require("path");
|
|
113
|
+
var import_node_path5 = require("path");
|
|
98
114
|
var import_utils = require("@antfu/utils");
|
|
99
115
|
var import_c122 = require("c12");
|
|
100
116
|
var import_jiti = require("jiti");
|
|
@@ -157,7 +173,6 @@ var ManifestContext = class {
|
|
|
157
173
|
* Must be called after construction.
|
|
158
174
|
*/
|
|
159
175
|
async setup() {
|
|
160
|
-
log(`manifest cwd: ${this.options.cwd}`);
|
|
161
176
|
const { config, unwatch } = await (0, import_c12.watchConfig)({
|
|
162
177
|
cwd: this.options.cwd,
|
|
163
178
|
name: "manifest",
|
|
@@ -186,7 +201,10 @@ function VitePluginUniManifest(userOptions = {}) {
|
|
|
186
201
|
};
|
|
187
202
|
}
|
|
188
203
|
function generateManifestConfigContent(content = {}) {
|
|
189
|
-
return
|
|
204
|
+
return `/* eslint-disable */
|
|
205
|
+
/* prettier-ignore */
|
|
206
|
+
// @ts-nocheck
|
|
207
|
+
// Auto-generated by @univa/core
|
|
190
208
|
export default ${JSON.stringify(content, null, 2)}
|
|
191
209
|
`;
|
|
192
210
|
}
|
|
@@ -200,6 +218,7 @@ function generateManifestConfigFile(content = {}, root) {
|
|
|
200
218
|
}
|
|
201
219
|
}
|
|
202
220
|
(0, import_node_fs2.writeFileSync)(configPath, newContent, "utf-8");
|
|
221
|
+
log(`Generated manifest config file: ${configPath}`);
|
|
203
222
|
}
|
|
204
223
|
function getManifestConfigPath(root) {
|
|
205
224
|
return (0, import_node_path2.join)(getUnivaDir(root), "manifest.config.ts");
|
|
@@ -211,106 +230,209 @@ function createManifestPlugin(userOptions = {}) {
|
|
|
211
230
|
});
|
|
212
231
|
}
|
|
213
232
|
|
|
233
|
+
// src/plugins/options.ts
|
|
234
|
+
var import_node_path3 = require("path");
|
|
235
|
+
var DEFAULT_DIRS = {
|
|
236
|
+
pages: "pages",
|
|
237
|
+
subPackages: [],
|
|
238
|
+
layouts: "layouts"
|
|
239
|
+
};
|
|
240
|
+
var DEFAULT_IMPORTS = {
|
|
241
|
+
apis: ["vue", "uni-app", "composables/**", "store/**", "hooks/**", "constants/**"],
|
|
242
|
+
components: ["components", "components-biz"]
|
|
243
|
+
};
|
|
244
|
+
var DEFAULT_UNI_PRESET = {
|
|
245
|
+
attributify: false
|
|
246
|
+
};
|
|
247
|
+
function resolveOptions2(userOptions, root) {
|
|
248
|
+
const srcDir = userOptions.srcDir || "src";
|
|
249
|
+
const srcDirAbs = (0, import_node_path3.resolve)(root, srcDir);
|
|
250
|
+
const autoScanPackages = scanSubPackages(srcDirAbs, SUB_PACKAGE_DIR_NAME);
|
|
251
|
+
const autoScanCompAsyncPackages = scanSubPackages(srcDirAbs, COMPONENTS_ASYNC_DIR_NAME);
|
|
252
|
+
const userSubPackages = userOptions.dirs?.subPackages ?? [];
|
|
253
|
+
const subPackages = [...userSubPackages, ...autoScanPackages, ...autoScanCompAsyncPackages];
|
|
254
|
+
log(`\u81EA\u52A8\u626B\u63CF\u5206\u5305\u76EE\u5F55\uFF1A${JSON.stringify({ subPackages })}`);
|
|
255
|
+
const dirs = {
|
|
256
|
+
pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
|
|
257
|
+
subPackages,
|
|
258
|
+
layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
|
|
259
|
+
};
|
|
260
|
+
const imports = {
|
|
261
|
+
apis: [...userOptions.imports?.apis ?? [], ...DEFAULT_IMPORTS.apis],
|
|
262
|
+
components: [...userOptions.imports?.components ?? [], ...DEFAULT_IMPORTS.components]
|
|
263
|
+
};
|
|
264
|
+
const unocss = {
|
|
265
|
+
presetLegacyCompat: userOptions.unocss?.presetLegacyCompat ?? true,
|
|
266
|
+
uniPreset: { ...DEFAULT_UNI_PRESET, ...userOptions.unocss?.uniPreset },
|
|
267
|
+
safelist: userOptions.unocss?.safelist ?? [],
|
|
268
|
+
themeColors: userOptions.unocss?.themeColors ?? {}
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
// 先展开用户配置(所有属性)
|
|
272
|
+
...userOptions,
|
|
273
|
+
// 解析后的属性覆盖原始属性(必填、已应用默认值)
|
|
274
|
+
srcDir,
|
|
275
|
+
srcDirAbs,
|
|
276
|
+
dirs,
|
|
277
|
+
imports,
|
|
278
|
+
unocss
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
214
282
|
// src/plugins/pages.ts
|
|
215
283
|
var import_node_fs3 = require("fs");
|
|
216
|
-
var
|
|
284
|
+
var import_node_path4 = require("path");
|
|
217
285
|
var import_vite_plugin_uni_pages = require("@uni-helper/vite-plugin-uni-pages");
|
|
218
286
|
function getPagesConfigPath(root) {
|
|
219
|
-
return (0,
|
|
287
|
+
return (0, import_node_path4.join)(getUnivaDir(root), "pages-config.ts");
|
|
220
288
|
}
|
|
221
289
|
function generatePagesConfigContent(content) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
export default ${JSON.stringify(rest, null, 2)}
|
|
290
|
+
return `/* eslint-disable */
|
|
291
|
+
/* prettier-ignore */
|
|
292
|
+
// @ts-nocheck
|
|
293
|
+
// Auto-generated by @univa/core
|
|
294
|
+
export default ${JSON.stringify(content, null, 2)}
|
|
228
295
|
`;
|
|
229
296
|
}
|
|
230
|
-
function generatePagesConfigFile(content, root) {
|
|
297
|
+
function generatePagesConfigFile(content, root, config) {
|
|
231
298
|
const pagesConfigPath = getPagesConfigPath(root);
|
|
232
299
|
const newContent = generatePagesConfigContent(content);
|
|
300
|
+
let needWrite = true;
|
|
233
301
|
if ((0, import_node_fs3.existsSync)(pagesConfigPath)) {
|
|
234
302
|
const existingContent = (0, import_node_fs3.readFileSync)(pagesConfigPath, "utf-8");
|
|
235
303
|
if (existingContent === newContent) {
|
|
236
|
-
|
|
304
|
+
log(`existingContent: ${existingContent}`);
|
|
305
|
+
log(`newContent: ${newContent}`);
|
|
306
|
+
log(`Pages config file ${pagesConfigPath} is up-to-date`);
|
|
307
|
+
needWrite = false;
|
|
237
308
|
}
|
|
238
309
|
}
|
|
239
|
-
(
|
|
310
|
+
if (needWrite) {
|
|
311
|
+
(0, import_node_fs3.writeFileSync)(pagesConfigPath, newContent, "utf-8");
|
|
312
|
+
log(`Generated pages config file: ${pagesConfigPath}`);
|
|
313
|
+
}
|
|
314
|
+
const resolvedPagesJSONPath = (0, import_node_path4.join)(config.srcDirAbs, PAGES_JSON_FILE_NAME);
|
|
315
|
+
log(`Generated pages JSON file: ${resolvedPagesJSONPath}`);
|
|
316
|
+
if (!(0, import_node_fs3.existsSync)(resolvedPagesJSONPath)) {
|
|
317
|
+
(0, import_node_fs3.writeFileSync)(resolvedPagesJSONPath, JSON.stringify(content, null, 2), "utf-8");
|
|
318
|
+
} else {
|
|
319
|
+
log(`Pages JSON file ${resolvedPagesJSONPath} is up-to-date`);
|
|
320
|
+
}
|
|
240
321
|
}
|
|
241
|
-
function createPagesPlugin(pluginOptions) {
|
|
322
|
+
function createPagesPlugin(pluginOptions, options) {
|
|
242
323
|
const result = (0, import_vite_plugin_uni_pages.VitePluginUniPages)({
|
|
243
324
|
dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
|
|
244
325
|
exclude: ["**/components/**/*.*"],
|
|
245
326
|
configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
|
|
327
|
+
onAfterMergePageMetaData: (ctx) => {
|
|
328
|
+
normalizePageNames(ctx);
|
|
329
|
+
},
|
|
246
330
|
...pluginOptions
|
|
247
331
|
});
|
|
248
332
|
return Array.isArray(result) ? result : [result];
|
|
249
333
|
}
|
|
334
|
+
function pathToPascalCase(path) {
|
|
335
|
+
if (!path) {
|
|
336
|
+
return "";
|
|
337
|
+
}
|
|
338
|
+
return path.split(/[/.-]/).filter(Boolean).map((str) => str.charAt(0).toUpperCase() + str.slice(1)).join("");
|
|
339
|
+
}
|
|
340
|
+
function normalizePageNames(pageContext) {
|
|
341
|
+
pageContext.pageMetaData.forEach((page) => {
|
|
342
|
+
if (page.name) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
page.name = pathToPascalCase(page.path);
|
|
346
|
+
});
|
|
347
|
+
pageContext.subPageMetaData.forEach((subPage) => {
|
|
348
|
+
subPage.pages.forEach((page) => {
|
|
349
|
+
if (subPage.root.startsWith(COMPONENTS_ASYNC_DIR_NAME)) {
|
|
350
|
+
page.layout = false;
|
|
351
|
+
}
|
|
352
|
+
if (page.name) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const fullPath = [subPage.root, page.path].filter(Boolean).join("/");
|
|
356
|
+
page.name = pathToPascalCase(fullPath);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
}
|
|
250
360
|
|
|
251
361
|
// src/plugins/context.ts
|
|
252
|
-
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
253
|
-
<template>
|
|
254
|
-
<KuRootView />
|
|
255
|
-
</template>
|
|
256
|
-
`;
|
|
257
362
|
var UnivaContext = class {
|
|
258
363
|
_server;
|
|
259
|
-
|
|
260
|
-
|
|
364
|
+
_config;
|
|
365
|
+
_configPath;
|
|
366
|
+
_jiti;
|
|
367
|
+
_resolveUserOptions;
|
|
368
|
+
/** 项目根目录(Vite root) */
|
|
261
369
|
root;
|
|
262
370
|
constructor(options) {
|
|
263
371
|
this.root = options.root;
|
|
372
|
+
this._jiti = (0, import_jiti.createJiti)(this.root);
|
|
264
373
|
}
|
|
265
374
|
/**
|
|
266
|
-
*
|
|
375
|
+
* 异步加载配置(c12)
|
|
267
376
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* 必须在 Vite 启动前调用(Univa() 初始化阶段),
|
|
272
|
-
* 否则在 configResolved 阶段创建 src 下新文件会触发 watcher add 事件,
|
|
273
|
-
* 导致 Vite 重编译与 VitePluginUniPages 的 pages.json 写入冲突(EPERM)。
|
|
377
|
+
* 支持更多格式:JSON/YAML/远程配置等
|
|
378
|
+
* 用于配置文件变化时重新加载
|
|
274
379
|
*/
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
log(`\u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${(0, import_utils.slash)(rootComponentPath)}`);
|
|
380
|
+
async loadUserConfig() {
|
|
381
|
+
const { config: userConfig, configFile } = await (0, import_c122.loadConfig)({
|
|
382
|
+
name: ID,
|
|
383
|
+
cwd: this.root,
|
|
384
|
+
defaults: this._config || {},
|
|
385
|
+
merger: mergeWithArrayOverride
|
|
386
|
+
});
|
|
387
|
+
this.resolveConfig(userConfig, configFile);
|
|
284
388
|
}
|
|
285
389
|
/**
|
|
286
|
-
*
|
|
390
|
+
* 同步加载配置(jiti)
|
|
391
|
+
*
|
|
392
|
+
* 用于插件初始化阶段,确保配置在插件创建前可用
|
|
287
393
|
*/
|
|
288
394
|
loadUserConfigSync() {
|
|
289
|
-
|
|
290
|
-
|
|
395
|
+
if (!this._jiti) {
|
|
396
|
+
log("Jiti \u672A\u521D\u59CB\u5316\uFF0C\u65E0\u6CD5\u52A0\u8F7D\u914D\u7F6E");
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const configFile = (0, import_node_path5.join)(this.root, `${ID}.config`);
|
|
291
400
|
try {
|
|
292
|
-
const configModule =
|
|
401
|
+
const configModule = this._jiti(configFile);
|
|
293
402
|
const userConfig = configModule?.default || configModule;
|
|
294
|
-
this.
|
|
295
|
-
|
|
296
|
-
|
|
403
|
+
this.resolveConfig(mergeWithArrayOverride({}, userConfig), configFile);
|
|
404
|
+
} catch (e) {
|
|
405
|
+
log(`\u52A0\u8F7D\u914D\u7F6E\u6587\u4EF6\u5931\u8D25\uFF1A${configFile}`, e);
|
|
297
406
|
}
|
|
298
407
|
}
|
|
299
408
|
/**
|
|
300
|
-
*
|
|
409
|
+
* 解析配置
|
|
410
|
+
*
|
|
411
|
+
* 统一处理配置加载后的逻辑:
|
|
412
|
+
* - 存储 raw config
|
|
413
|
+
* - 解析为 resolved options(应用默认值、扫描目录)
|
|
301
414
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.
|
|
310
|
-
|
|
415
|
+
resolveConfig(userConfig, configFile) {
|
|
416
|
+
this._config = userConfig;
|
|
417
|
+
this._configPath = configFile || "";
|
|
418
|
+
this._resolveUserOptions = resolveOptions2(userConfig, this.root);
|
|
419
|
+
}
|
|
420
|
+
/** 获取解析后的配置 */
|
|
421
|
+
get resolveUserOptions() {
|
|
422
|
+
return this._resolveUserOptions;
|
|
423
|
+
}
|
|
424
|
+
/** 获取原始配置 */
|
|
425
|
+
get config() {
|
|
426
|
+
return this._config;
|
|
427
|
+
}
|
|
428
|
+
/** 获取配置文件路径 */
|
|
429
|
+
get configPath() {
|
|
430
|
+
return this._configPath;
|
|
311
431
|
}
|
|
312
432
|
/**
|
|
313
433
|
* 设置 Vite 开发服务器
|
|
434
|
+
*
|
|
435
|
+
* 监听配置文件变化,触发重新加载
|
|
314
436
|
*/
|
|
315
437
|
setupViteServer(server) {
|
|
316
438
|
if (this._server === server)
|
|
@@ -321,101 +443,167 @@ var UnivaContext = class {
|
|
|
321
443
|
/**
|
|
322
444
|
* 设置文件监听器
|
|
323
445
|
*
|
|
324
|
-
* 监听 univa.config.ts
|
|
446
|
+
* 监听 univa.config.ts 变化:
|
|
447
|
+
* - 重新加载配置
|
|
448
|
+
* - 更新生成文件
|
|
449
|
+
* - 触发 HMR
|
|
325
450
|
*/
|
|
326
451
|
setupWatcher(watcher) {
|
|
327
|
-
if (!this.
|
|
452
|
+
if (!this._configPath)
|
|
328
453
|
return;
|
|
329
|
-
|
|
330
|
-
watcher.add(this.configPath);
|
|
454
|
+
watcher.add(this._configPath);
|
|
331
455
|
watcher.on("change", async (filePath) => {
|
|
332
|
-
filePath
|
|
333
|
-
const configPath = (0, import_utils.slash)(this.configPath || "");
|
|
334
|
-
if (filePath !== configPath) {
|
|
456
|
+
if ((0, import_utils.slash)(filePath) !== (0, import_utils.slash)(this._configPath || ""))
|
|
335
457
|
return;
|
|
336
|
-
}
|
|
337
458
|
await this.updateConfig();
|
|
338
459
|
this.onUpdate();
|
|
339
460
|
});
|
|
340
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* 更新配置
|
|
464
|
+
*
|
|
465
|
+
* 配置文件变化时:
|
|
466
|
+
* - 异步加载新配置
|
|
467
|
+
* - 更新生成文件
|
|
468
|
+
*/
|
|
341
469
|
async updateConfig() {
|
|
342
|
-
await this.
|
|
470
|
+
await this.loadUserConfig();
|
|
343
471
|
this.updateGeneratedFiles();
|
|
344
472
|
}
|
|
345
473
|
/**
|
|
346
|
-
*
|
|
474
|
+
* 更新生成文件
|
|
347
475
|
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* 注意:不在此处生成 src/App.ku.vue,避免在 configResolved 阶段
|
|
352
|
-
* 创建 src 下新文件触发 watcher add 事件,导致 Vite 重编译
|
|
353
|
-
* 与 VitePluginUniPages 的 pages.json 写入冲突(EPERM)。
|
|
354
|
-
* App.ku.vue 的生成在 Univa() 初始化阶段完成。
|
|
476
|
+
* 根据配置生成:
|
|
477
|
+
* - .univa/pages-config.ts(VitePluginUniPages 依赖)
|
|
478
|
+
* - .univa/manifest-config.ts(可选)
|
|
355
479
|
*/
|
|
356
480
|
updateGeneratedFiles() {
|
|
357
|
-
const
|
|
358
|
-
if (
|
|
359
|
-
|
|
481
|
+
const resolved = this._resolveUserOptions;
|
|
482
|
+
if (!resolved)
|
|
483
|
+
return;
|
|
484
|
+
const pagesConfig = resolved.pages || {};
|
|
485
|
+
if (resolved.homePage) {
|
|
486
|
+
pagesConfig.pages = pagesConfig.pages || [];
|
|
487
|
+
pagesConfig.pages.unshift(resolved.homePage);
|
|
488
|
+
log(`\u5DF2\u63D2\u5165\u9996\u9875\u914D\u7F6E\uFF1A${JSON.stringify(resolved.homePage)}`);
|
|
360
489
|
}
|
|
361
|
-
|
|
490
|
+
log(`\u751F\u6210 pages \u914D\u7F6E\uFF1A${JSON.stringify(pagesConfig)}`);
|
|
491
|
+
generatePagesConfigFile(pagesConfig, this.root, resolved);
|
|
492
|
+
const manifestConfig = resolved.manifest;
|
|
362
493
|
if (manifestConfig) {
|
|
363
494
|
generateManifestConfigFile(manifestConfig, this.root);
|
|
364
495
|
}
|
|
365
|
-
const pagesTsPath = getPagesConfigPath(this.root);
|
|
366
|
-
const emptyContent = `// Auto-generated by @univa/core
|
|
367
|
-
export default {}
|
|
368
|
-
`;
|
|
369
|
-
if (!(0, import_node_fs4.existsSync)(pagesTsPath)) {
|
|
370
|
-
(0, import_node_fs4.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
|
|
371
|
-
} else if (!pagesConfig) {
|
|
372
|
-
if ((0, import_node_fs4.readFileSync)(pagesTsPath, "utf-8") !== emptyContent) {
|
|
373
|
-
(0, import_node_fs4.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
496
|
}
|
|
377
497
|
/**
|
|
378
|
-
* 更新回调
|
|
379
498
|
* 触发 HMR
|
|
499
|
+
*
|
|
500
|
+
* 配置变化后通知浏览器刷新
|
|
380
501
|
*/
|
|
381
502
|
onUpdate() {
|
|
382
|
-
if (!this._server)
|
|
503
|
+
if (!this._server)
|
|
383
504
|
return;
|
|
384
|
-
}
|
|
385
505
|
this._server.ws.send({
|
|
386
506
|
type: "full-reload"
|
|
387
507
|
});
|
|
388
508
|
}
|
|
389
509
|
};
|
|
390
510
|
|
|
391
|
-
// src/plugins/
|
|
392
|
-
var
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
function
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
511
|
+
// src/plugins/root.ts
|
|
512
|
+
var import_node_fs4 = require("fs");
|
|
513
|
+
var import_node_path6 = require("path");
|
|
514
|
+
var import_utils2 = require("@antfu/utils");
|
|
515
|
+
var import_root = __toESM(require("@uni-ku/root"), 1);
|
|
516
|
+
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
517
|
+
<template>
|
|
518
|
+
<KuRootView />
|
|
519
|
+
</template>
|
|
520
|
+
`;
|
|
521
|
+
function ensureRootComponent(fileName, srcDirAbs) {
|
|
522
|
+
const rootComponentPath = (0, import_node_path6.join)(srcDirAbs, fileName);
|
|
523
|
+
if ((0, import_node_fs4.existsSync)(rootComponentPath)) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
(0, import_node_fs4.writeFileSync)(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
|
|
527
|
+
log(`\u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${(0, import_utils2.slash)(rootComponentPath)}`);
|
|
528
|
+
}
|
|
529
|
+
function createRootPlugin(options) {
|
|
530
|
+
let rootFileName = `${ROOT_NAME}.vue`;
|
|
531
|
+
if (options.overrides?.root?.rootFileName) {
|
|
532
|
+
rootFileName = `${options.overrides.root.rootFileName}.vue`;
|
|
533
|
+
}
|
|
534
|
+
ensureRootComponent(rootFileName, options.srcDirAbs);
|
|
535
|
+
return (0, import_root.default)({
|
|
536
|
+
enabledVirtualHost: true,
|
|
537
|
+
enabledGlobalRef: true,
|
|
538
|
+
rootFileName: ROOT_NAME,
|
|
539
|
+
excludePages: [
|
|
540
|
+
`${COMPONENTS_ASYNC_DIR_NAME}/**/*.*`
|
|
541
|
+
],
|
|
542
|
+
...options.overrides?.root
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/plugins/unocss.ts
|
|
547
|
+
var import_unocss_preset_uni = require("@uni-helper/unocss-preset-uni");
|
|
548
|
+
var import_preset_legacy_compat = __toESM(require("@unocss/preset-legacy-compat"), 1);
|
|
549
|
+
var import_unocss = require("unocss");
|
|
550
|
+
var import_vite2 = __toESM(require("unocss/vite"), 1);
|
|
551
|
+
function presetUniva(userOptions) {
|
|
552
|
+
const presets = [];
|
|
553
|
+
if (userOptions.presetLegacyCompat) {
|
|
554
|
+
presets.push((0, import_preset_legacy_compat.default)({
|
|
555
|
+
commaStyleColorFunction: true,
|
|
556
|
+
legacyColorSpace: true
|
|
557
|
+
}));
|
|
558
|
+
}
|
|
412
559
|
return {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
560
|
+
name: `${ID}-preset`,
|
|
561
|
+
presets: [
|
|
562
|
+
(0, import_unocss_preset_uni.presetUni)(userOptions.uniPreset),
|
|
563
|
+
(0, import_unocss.presetIcons)({
|
|
564
|
+
scale: 1.2,
|
|
565
|
+
warn: true,
|
|
566
|
+
extraProperties: {
|
|
567
|
+
"display": "inline-block",
|
|
568
|
+
"vertical-align": "middle"
|
|
569
|
+
}
|
|
570
|
+
}),
|
|
571
|
+
...presets
|
|
572
|
+
],
|
|
573
|
+
shortcuts: [
|
|
574
|
+
["border-s", "border border-solid"],
|
|
575
|
+
["wh-full", "w-full h-full"],
|
|
576
|
+
["f-c-c", "flex justify-center items-center"],
|
|
577
|
+
["f-col-c", "flex-col justify-center items-center"],
|
|
578
|
+
["flex-items", "flex items-center"],
|
|
579
|
+
["flex-justify", "flex justify-center"],
|
|
580
|
+
["flex-col", "flex flex-col"]
|
|
581
|
+
],
|
|
582
|
+
transformers: [(0, import_unocss.transformerDirectives)(), (0, import_unocss.transformerVariantGroup)()],
|
|
583
|
+
rules: [
|
|
584
|
+
[
|
|
585
|
+
"p-safe",
|
|
586
|
+
{
|
|
587
|
+
padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
|
|
588
|
+
}
|
|
589
|
+
],
|
|
590
|
+
["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
|
|
591
|
+
["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
|
|
592
|
+
],
|
|
593
|
+
safelist: userOptions.safelist,
|
|
594
|
+
theme: {
|
|
595
|
+
colors: userOptions.themeColors
|
|
596
|
+
}
|
|
417
597
|
};
|
|
418
598
|
}
|
|
599
|
+
function createUnocssPlugin(univaOptions, unocssOptions = {}) {
|
|
600
|
+
return (0, import_vite2.default)({
|
|
601
|
+
presets: [
|
|
602
|
+
presetUniva(univaOptions)
|
|
603
|
+
],
|
|
604
|
+
...unocssOptions
|
|
605
|
+
});
|
|
606
|
+
}
|
|
419
607
|
|
|
420
608
|
// src/plugins/index.ts
|
|
421
609
|
var context;
|
|
@@ -423,10 +611,6 @@ function createCorePlugin() {
|
|
|
423
611
|
return {
|
|
424
612
|
name: "vite-plugin-univa",
|
|
425
613
|
enforce: "pre",
|
|
426
|
-
async configResolved() {
|
|
427
|
-
await context.loadUserConfigAsync();
|
|
428
|
-
context.updateGeneratedFiles();
|
|
429
|
-
},
|
|
430
614
|
configureServer(server) {
|
|
431
615
|
context.setupViteServer(server);
|
|
432
616
|
}
|
|
@@ -464,21 +648,14 @@ function createUnivaPlugins(resolved) {
|
|
|
464
648
|
plugins.push(...createPagesPlugin({
|
|
465
649
|
dir: `${srcDir}/${resolved.dirs.pages}`,
|
|
466
650
|
subPackages: resolved.dirs.subPackages.map((p) => `${srcDir}/${p}`),
|
|
651
|
+
debug: resolved.debug,
|
|
467
652
|
...resolved.overrides?.pages
|
|
468
|
-
}));
|
|
653
|
+
}, resolved));
|
|
469
654
|
plugins.push((0, import_vite_plugin_uni_layouts.VitePluginUniLayouts)({
|
|
470
655
|
layoutDir: `${srcDir}/${resolved.dirs.layouts}`,
|
|
471
656
|
...resolved.overrides?.layouts
|
|
472
657
|
}));
|
|
473
|
-
plugins.push((
|
|
474
|
-
enabledVirtualHost: true,
|
|
475
|
-
enabledGlobalRef: true,
|
|
476
|
-
rootFileName: ROOT_NAME,
|
|
477
|
-
excludePages: [
|
|
478
|
-
"components-async/**/*.*"
|
|
479
|
-
],
|
|
480
|
-
...resolved.overrides?.root
|
|
481
|
-
}));
|
|
658
|
+
plugins.push(createRootPlugin(resolved));
|
|
482
659
|
plugins.push((0, import_vite_plugin_uni_components.default)({
|
|
483
660
|
dirs: resolved.imports.components.map((c) => `${srcDir}/${c}`),
|
|
484
661
|
dts: `${UNIVA_DIR_NAME}/components.d.ts`,
|
|
@@ -490,7 +667,13 @@ function createUnivaPlugins(resolved) {
|
|
|
490
667
|
...resolved.overrides?.manifest
|
|
491
668
|
}));
|
|
492
669
|
plugins.push(...(0, import_plugin_uni.default)());
|
|
493
|
-
plugins.push(
|
|
670
|
+
plugins.push((0, import_vite_plugin_uni_polyfill.default)());
|
|
671
|
+
plugins.push(createUnocssPlugin(resolved.unocss, resolved.overrides?.unocss));
|
|
672
|
+
plugins.push((0, import_bundle_optimizer.default)({
|
|
673
|
+
enable: true,
|
|
674
|
+
logger: resolved.debug,
|
|
675
|
+
...resolved.overrides?.optimization
|
|
676
|
+
}));
|
|
494
677
|
const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
|
|
495
678
|
const autoImportPlugin = (0, import_vite3.default)({
|
|
496
679
|
imports: presets,
|
|
@@ -511,26 +694,23 @@ function Univa() {
|
|
|
511
694
|
});
|
|
512
695
|
ensureUnivaDir(context.root);
|
|
513
696
|
context.loadUserConfigSync();
|
|
514
|
-
setDebug(context.
|
|
515
|
-
context.
|
|
516
|
-
|
|
517
|
-
log("\u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
|
|
518
|
-
return createUnivaPlugins(resolved);
|
|
697
|
+
setDebug(context.resolveUserOptions.debug ?? false);
|
|
698
|
+
context.updateGeneratedFiles();
|
|
699
|
+
return createUnivaPlugins(context.resolveUserOptions);
|
|
519
700
|
}
|
|
520
701
|
var plugins_default = Univa;
|
|
521
702
|
|
|
522
703
|
// src/index.ts
|
|
523
|
-
var
|
|
704
|
+
var import_unocss_preset_uni2 = require("@uni-helper/unocss-preset-uni");
|
|
524
705
|
var import_vite_plugin_uni_components2 = require("@uni-helper/vite-plugin-uni-components");
|
|
525
706
|
var import_vite_plugin_uni_components3 = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
|
|
526
707
|
var import_vite_plugin_uni_layouts2 = require("@uni-helper/vite-plugin-uni-layouts");
|
|
527
708
|
var import_vite_plugin_uni_pages2 = require("@uni-helper/vite-plugin-uni-pages");
|
|
528
|
-
var
|
|
709
|
+
var import_root3 = __toESM(require("@uni-ku/root"), 1);
|
|
529
710
|
var import_vite4 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
530
711
|
// Annotate the CommonJS export names for ESM import in node:
|
|
531
712
|
0 && (module.exports = {
|
|
532
713
|
AutoImport,
|
|
533
|
-
PageContext,
|
|
534
714
|
UniKuRoot,
|
|
535
715
|
Univa,
|
|
536
716
|
VitePluginUniComponents,
|