@univa/core 0.0.8 → 0.1.0
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 +441 -435
- package/THIRD-PARTY-NOTICES +216 -0
- package/dist/global.d.ts +5 -4
- package/dist/index.cjs +143 -14
- package/dist/index.d.cts +24 -6
- package/dist/index.d.ts +24 -6
- package/dist/index.js +146 -16
- package/package.json +16 -14
package/dist/index.js
CHANGED
|
@@ -7,18 +7,21 @@ function defineConfig(config) {
|
|
|
7
7
|
import Uni from "@uni-helper/plugin-uni";
|
|
8
8
|
import VitePluginUniComponents from "@uni-helper/vite-plugin-uni-components";
|
|
9
9
|
import { VitePluginUniLayouts } from "@uni-helper/vite-plugin-uni-layouts";
|
|
10
|
+
import Optimization from "@uni-ku/bundle-optimizer";
|
|
10
11
|
import UniKuRoot from "@uni-ku/root";
|
|
11
|
-
import UnoCSS from "unocss/vite";
|
|
12
12
|
import AutoImport from "unplugin-auto-import/vite";
|
|
13
|
+
import UniPolyfill from "vite-plugin-uni-polyfill";
|
|
13
14
|
|
|
14
15
|
// src/constant.ts
|
|
15
16
|
var ID = "univa";
|
|
16
17
|
var UNIVA_DIR_NAME = `.${ID}`;
|
|
17
18
|
var ROOT_NAME = `${ID}.root`;
|
|
19
|
+
var COMPONENTS_ASYNC_DIR_NAME = "components-async";
|
|
20
|
+
var SUB_PACKAGE_DIR_NAME = "app";
|
|
18
21
|
|
|
19
22
|
// src/utils/fs.ts
|
|
20
|
-
import { existsSync, mkdirSync } from "fs";
|
|
21
|
-
import { join } from "path";
|
|
23
|
+
import { existsSync, mkdirSync, readdirSync, statSync } from "fs";
|
|
24
|
+
import { join, posix } from "path";
|
|
22
25
|
function ensureDir(dir) {
|
|
23
26
|
if (!existsSync(dir)) {
|
|
24
27
|
mkdirSync(dir, { recursive: true });
|
|
@@ -32,6 +35,21 @@ function ensureUnivaDir(cwd) {
|
|
|
32
35
|
ensureDir(dir);
|
|
33
36
|
return dir;
|
|
34
37
|
}
|
|
38
|
+
function getSubDirectories(dirPath) {
|
|
39
|
+
if (!existsSync(dirPath)) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const entries = readdirSync(dirPath);
|
|
43
|
+
return entries.filter((entry) => {
|
|
44
|
+
const fullPath = join(dirPath, entry);
|
|
45
|
+
return statSync(fullPath).isDirectory();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function scanSubPackages(srcDir, subPackageRoot) {
|
|
49
|
+
const rootPath = join(srcDir, subPackageRoot);
|
|
50
|
+
const subDirs = getSubDirectories(rootPath);
|
|
51
|
+
return subDirs.map((name) => posix.join(subPackageRoot, name));
|
|
52
|
+
}
|
|
35
53
|
|
|
36
54
|
// src/utils/logger.ts
|
|
37
55
|
var debugMode = false;
|
|
@@ -175,7 +193,6 @@ function generatePagesConfigContent(content) {
|
|
|
175
193
|
void pages;
|
|
176
194
|
void subPackages;
|
|
177
195
|
return `// Auto-generated by @univa/core
|
|
178
|
-
// \u6765\u6E90\uFF1Auniva.config.ts \u7684 pages \u5B57\u6BB5
|
|
179
196
|
export default ${JSON.stringify(rest, null, 2)}
|
|
180
197
|
`;
|
|
181
198
|
}
|
|
@@ -195,10 +212,39 @@ function createPagesPlugin(pluginOptions) {
|
|
|
195
212
|
dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
|
|
196
213
|
exclude: ["**/components/**/*.*"],
|
|
197
214
|
configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
|
|
215
|
+
onAfterMergePageMetaData: (ctx) => {
|
|
216
|
+
normalizePageNames(ctx);
|
|
217
|
+
},
|
|
198
218
|
...pluginOptions
|
|
199
219
|
});
|
|
200
220
|
return Array.isArray(result) ? result : [result];
|
|
201
221
|
}
|
|
222
|
+
function pathToPascalCase(path) {
|
|
223
|
+
if (!path) {
|
|
224
|
+
return "";
|
|
225
|
+
}
|
|
226
|
+
return path.split(/[/.-]/).filter(Boolean).map((str) => str.charAt(0).toUpperCase() + str.slice(1)).join("");
|
|
227
|
+
}
|
|
228
|
+
function normalizePageNames(pageContext) {
|
|
229
|
+
pageContext.pageMetaData.forEach((page) => {
|
|
230
|
+
if (page.name) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
page.name = pathToPascalCase(page.path);
|
|
234
|
+
});
|
|
235
|
+
pageContext.subPageMetaData.forEach((subPage) => {
|
|
236
|
+
subPage.pages.forEach((page) => {
|
|
237
|
+
if (subPage.root.startsWith(COMPONENTS_ASYNC_DIR_NAME)) {
|
|
238
|
+
page.layout = false;
|
|
239
|
+
}
|
|
240
|
+
if (page.name) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const fullPath = [subPage.root, page.path].filter(Boolean).join("/");
|
|
244
|
+
page.name = pathToPascalCase(fullPath);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
202
248
|
|
|
203
249
|
// src/plugins/context.ts
|
|
204
250
|
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
@@ -341,34 +387,113 @@ export default {}
|
|
|
341
387
|
};
|
|
342
388
|
|
|
343
389
|
// src/plugins/options.ts
|
|
390
|
+
import { resolve as resolve2 } from "path";
|
|
344
391
|
var DEFAULT_DIRS = {
|
|
345
392
|
pages: "pages",
|
|
346
|
-
subPackages: [
|
|
393
|
+
subPackages: [],
|
|
347
394
|
layouts: "layouts"
|
|
348
395
|
};
|
|
349
396
|
var DEFAULT_IMPORTS = {
|
|
350
|
-
apis: ["vue", "uni-app", "composables/**", "
|
|
351
|
-
components: ["components
|
|
397
|
+
apis: ["vue", "uni-app", "composables/**", "store/**", "hooks/**", "constants/**"],
|
|
398
|
+
components: ["components", "components-biz"]
|
|
399
|
+
};
|
|
400
|
+
var DEFAULT_UNI_PRESET = {
|
|
401
|
+
attributify: false
|
|
352
402
|
};
|
|
353
|
-
function resolveOptions2(userOptions) {
|
|
403
|
+
function resolveOptions2(userOptions, root) {
|
|
354
404
|
const srcDir = userOptions.srcDir || "src";
|
|
405
|
+
const srcDirAbs = resolve2(root, srcDir);
|
|
406
|
+
const autoScanPackages = scanSubPackages(srcDirAbs, SUB_PACKAGE_DIR_NAME);
|
|
407
|
+
const autoScanCompAsyncPackages = scanSubPackages(srcDirAbs, COMPONENTS_ASYNC_DIR_NAME);
|
|
408
|
+
const userSubPackages = userOptions.dirs?.subPackages ?? [];
|
|
409
|
+
const subPackages = [...userSubPackages, ...autoScanPackages, ...autoScanCompAsyncPackages];
|
|
410
|
+
log(`autoScanPackages: ${JSON.stringify({ subPackages })}`);
|
|
355
411
|
const dirs = {
|
|
356
412
|
pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
|
|
357
|
-
subPackages
|
|
413
|
+
subPackages,
|
|
358
414
|
layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
|
|
359
415
|
};
|
|
360
416
|
const imports = {
|
|
361
417
|
apis: userOptions.imports?.apis ?? DEFAULT_IMPORTS.apis,
|
|
362
418
|
components: userOptions.imports?.components ?? DEFAULT_IMPORTS.components
|
|
363
419
|
};
|
|
420
|
+
const unocss = {
|
|
421
|
+
presetLegacyCompat: userOptions.unocss?.presetLegacyCompat ?? true,
|
|
422
|
+
uniPreset: userOptions.unocss?.uniPreset ?? DEFAULT_UNI_PRESET,
|
|
423
|
+
safelist: userOptions.unocss?.safelist ?? [],
|
|
424
|
+
themeColors: userOptions.unocss?.themeColors ?? {}
|
|
425
|
+
};
|
|
364
426
|
return {
|
|
365
427
|
srcDir,
|
|
366
428
|
dirs,
|
|
429
|
+
unocss,
|
|
367
430
|
imports,
|
|
368
431
|
overrides: userOptions.overrides
|
|
369
432
|
};
|
|
370
433
|
}
|
|
371
434
|
|
|
435
|
+
// src/plugins/unocss.ts
|
|
436
|
+
import { presetUni } from "@uni-helper/unocss-preset-uni";
|
|
437
|
+
import presetLegacyCompat from "@unocss/preset-legacy-compat";
|
|
438
|
+
import { presetIcons, transformerDirectives, transformerVariantGroup } from "unocss";
|
|
439
|
+
import UnoCSS from "unocss/vite";
|
|
440
|
+
function presetUniva(userOptions) {
|
|
441
|
+
const presets = [];
|
|
442
|
+
if (userOptions.presetLegacyCompat) {
|
|
443
|
+
presets.push(presetLegacyCompat({
|
|
444
|
+
commaStyleColorFunction: true,
|
|
445
|
+
legacyColorSpace: true
|
|
446
|
+
}));
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
name: `${ID}-preset`,
|
|
450
|
+
presets: [
|
|
451
|
+
presetUni(userOptions.uniPreset),
|
|
452
|
+
presetIcons({
|
|
453
|
+
scale: 1.2,
|
|
454
|
+
warn: true,
|
|
455
|
+
extraProperties: {
|
|
456
|
+
"display": "inline-block",
|
|
457
|
+
"vertical-align": "middle"
|
|
458
|
+
}
|
|
459
|
+
}),
|
|
460
|
+
...presets
|
|
461
|
+
],
|
|
462
|
+
shortcuts: [
|
|
463
|
+
["border-s", "border border-solid"],
|
|
464
|
+
["wh-full", "w-full h-full"],
|
|
465
|
+
["f-c-c", "flex justify-center items-center"],
|
|
466
|
+
["f-col-c", "flex-col justify-center items-center"],
|
|
467
|
+
["flex-items", "flex items-center"],
|
|
468
|
+
["flex-justify", "flex justify-center"],
|
|
469
|
+
["flex-col", "flex flex-col"]
|
|
470
|
+
],
|
|
471
|
+
transformers: [transformerDirectives(), transformerVariantGroup()],
|
|
472
|
+
rules: [
|
|
473
|
+
[
|
|
474
|
+
"p-safe",
|
|
475
|
+
{
|
|
476
|
+
padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
|
|
480
|
+
["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
|
|
481
|
+
],
|
|
482
|
+
safelist: userOptions.safelist,
|
|
483
|
+
theme: {
|
|
484
|
+
colors: userOptions.themeColors
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function createUnocssPlugin(univaOptions, unocssOptions = {}) {
|
|
489
|
+
return UnoCSS({
|
|
490
|
+
presets: [
|
|
491
|
+
presetUniva(univaOptions)
|
|
492
|
+
],
|
|
493
|
+
...unocssOptions
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
372
497
|
// src/plugins/index.ts
|
|
373
498
|
var context;
|
|
374
499
|
function createCorePlugin() {
|
|
@@ -427,7 +552,7 @@ function createUnivaPlugins(resolved) {
|
|
|
427
552
|
enabledGlobalRef: true,
|
|
428
553
|
rootFileName: ROOT_NAME,
|
|
429
554
|
excludePages: [
|
|
430
|
-
|
|
555
|
+
`${COMPONENTS_ASYNC_DIR_NAME}/**/*.*`
|
|
431
556
|
],
|
|
432
557
|
...resolved.overrides?.root
|
|
433
558
|
}));
|
|
@@ -442,7 +567,13 @@ function createUnivaPlugins(resolved) {
|
|
|
442
567
|
...resolved.overrides?.manifest
|
|
443
568
|
}));
|
|
444
569
|
plugins.push(...Uni());
|
|
445
|
-
plugins.push(
|
|
570
|
+
plugins.push(UniPolyfill());
|
|
571
|
+
plugins.push(createUnocssPlugin(resolved.unocss, resolved.overrides?.unocss));
|
|
572
|
+
plugins.push(Optimization({
|
|
573
|
+
enable: true,
|
|
574
|
+
logger: resolved.debug,
|
|
575
|
+
...resolved.overrides?.optimization
|
|
576
|
+
}));
|
|
446
577
|
const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
|
|
447
578
|
const autoImportPlugin = AutoImport({
|
|
448
579
|
imports: presets,
|
|
@@ -465,23 +596,22 @@ function Univa() {
|
|
|
465
596
|
context.loadUserConfigSync();
|
|
466
597
|
setDebug(context.config?.debug ?? false);
|
|
467
598
|
context.ensureRootComponent(`${ROOT_NAME}.vue`);
|
|
468
|
-
const resolved = resolveOptions2(context.config || {});
|
|
599
|
+
const resolved = resolveOptions2(context.config || {}, context.root);
|
|
469
600
|
log("\u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
|
|
470
601
|
return createUnivaPlugins(resolved);
|
|
471
602
|
}
|
|
472
603
|
var plugins_default = Univa;
|
|
473
604
|
|
|
474
605
|
// src/index.ts
|
|
475
|
-
import { presetUni } from "@uni-helper/unocss-preset-uni";
|
|
606
|
+
import { presetUni as presetUni2 } from "@uni-helper/unocss-preset-uni";
|
|
476
607
|
import { camelCase, kebabCase, pascalCase } from "@uni-helper/vite-plugin-uni-components";
|
|
477
608
|
import { default as default2 } from "@uni-helper/vite-plugin-uni-components";
|
|
478
609
|
import { VitePluginUniLayouts as VitePluginUniLayouts2 } from "@uni-helper/vite-plugin-uni-layouts";
|
|
479
|
-
import {
|
|
610
|
+
import { VitePluginUniPages as VitePluginUniPages2 } from "@uni-helper/vite-plugin-uni-pages";
|
|
480
611
|
import { default as default3 } from "@uni-ku/root";
|
|
481
612
|
import { default as default4 } from "unplugin-auto-import/vite";
|
|
482
613
|
export {
|
|
483
614
|
default4 as AutoImport,
|
|
484
|
-
PageContext,
|
|
485
615
|
default3 as UniKuRoot,
|
|
486
616
|
plugins_default as Univa,
|
|
487
617
|
default2 as VitePluginUniComponents,
|
|
@@ -492,5 +622,5 @@ export {
|
|
|
492
622
|
defineConfig,
|
|
493
623
|
kebabCase,
|
|
494
624
|
pascalCase,
|
|
495
|
-
presetUni
|
|
625
|
+
presetUni2 as presetUni
|
|
496
626
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univa/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"description": "🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验",
|
|
6
6
|
"author": "lianghang <libre1103@163.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"files": [
|
|
50
50
|
"LICENSE",
|
|
51
51
|
"README.md",
|
|
52
|
+
"THIRD-PARTY-NOTICES",
|
|
52
53
|
"dist"
|
|
53
54
|
],
|
|
54
55
|
"engines": {
|
|
@@ -58,15 +59,11 @@
|
|
|
58
59
|
"access": "public",
|
|
59
60
|
"registry": "https://registry.npmjs.org/"
|
|
60
61
|
},
|
|
61
|
-
"scripts": {
|
|
62
|
-
"build": "node scripts/build.mjs",
|
|
63
|
-
"dev": "tsup --watch"
|
|
64
|
-
},
|
|
65
62
|
"peerDependencies": {
|
|
66
63
|
"vite": "^5.2.8"
|
|
67
64
|
},
|
|
68
65
|
"dependencies": {
|
|
69
|
-
"@antfu/utils": "
|
|
66
|
+
"@antfu/utils": "^9.3.0",
|
|
70
67
|
"@dcloudio/types": "3.4.28",
|
|
71
68
|
"@uni-helper/eslint-config": "0.7.4",
|
|
72
69
|
"@uni-helper/plugin-uni": "0.1.0",
|
|
@@ -77,12 +74,13 @@
|
|
|
77
74
|
"@uni-helper/vite-plugin-uni-layouts": "0.1.11",
|
|
78
75
|
"@uni-helper/vite-plugin-uni-manifest": "0.4.1",
|
|
79
76
|
"@uni-helper/vite-plugin-uni-pages": "0.4.6",
|
|
77
|
+
"@uni-ku/bundle-optimizer": "2.2.0",
|
|
80
78
|
"@uni-ku/root": "1.4.1",
|
|
81
79
|
"@unocss/eslint-plugin": "66.6.7",
|
|
82
80
|
"@unocss/preset-legacy-compat": "66.0.0",
|
|
83
81
|
"c12": "3.3.4",
|
|
84
82
|
"defu": "6.1.7",
|
|
85
|
-
"eslint": "
|
|
83
|
+
"eslint": "^10.5.0",
|
|
86
84
|
"jiti": "2.7.0",
|
|
87
85
|
"sass": "1.99.0",
|
|
88
86
|
"unocss": "66.0.0",
|
|
@@ -90,11 +88,15 @@
|
|
|
90
88
|
"vite-plugin-uni-polyfill": "0.1.0"
|
|
91
89
|
},
|
|
92
90
|
"devDependencies": {
|
|
93
|
-
"@dcloudio/uni-app": "
|
|
94
|
-
"@types/node": "
|
|
95
|
-
"tsup": "
|
|
96
|
-
"typescript": "
|
|
97
|
-
"vite": "
|
|
98
|
-
"vue": "
|
|
91
|
+
"@dcloudio/uni-app": "3.0.0-5000720260410001",
|
|
92
|
+
"@types/node": "^24.13.2",
|
|
93
|
+
"tsup": "^8.5.1",
|
|
94
|
+
"typescript": "^5.9.3",
|
|
95
|
+
"vite": "^5.2.8",
|
|
96
|
+
"vue": "~3.4.38"
|
|
97
|
+
},
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "node scripts/build.mjs",
|
|
100
|
+
"dev": "tsup --watch"
|
|
99
101
|
}
|
|
100
|
-
}
|
|
102
|
+
}
|