@univa/core 0.0.9 → 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/dist/global.d.ts +1 -0
- 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 +2 -1
package/dist/global.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ 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
|
-
PageContext: () => import_vite_plugin_uni_pages2.PageContext,
|
|
35
34
|
UniKuRoot: () => import_root2.default,
|
|
36
35
|
Univa: () => plugins_default,
|
|
37
36
|
VitePluginUniComponents: () => import_vite_plugin_uni_components3.default,
|
|
@@ -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");
|
|
57
|
+
var import_bundle_optimizer = __toESM(require("@uni-ku/bundle-optimizer"), 1);
|
|
58
58
|
var import_root = __toESM(require("@uni-ku/root"), 1);
|
|
59
|
-
var import_vite2 = __toESM(require("unocss/vite"), 1);
|
|
60
59
|
var import_vite3 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
60
|
+
var import_vite_plugin_uni_polyfill = __toESM(require("vite-plugin-uni-polyfill"), 1);
|
|
61
61
|
|
|
62
62
|
// src/constant.ts
|
|
63
63
|
var ID = "univa";
|
|
64
64
|
var UNIVA_DIR_NAME = `.${ID}`;
|
|
65
65
|
var ROOT_NAME = `${ID}.root`;
|
|
66
|
+
var COMPONENTS_ASYNC_DIR_NAME = "components-async";
|
|
67
|
+
var SUB_PACKAGE_DIR_NAME = "app";
|
|
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;
|
|
@@ -223,7 +240,6 @@ function generatePagesConfigContent(content) {
|
|
|
223
240
|
void pages;
|
|
224
241
|
void subPackages;
|
|
225
242
|
return `// Auto-generated by @univa/core
|
|
226
|
-
// \u6765\u6E90\uFF1Auniva.config.ts \u7684 pages \u5B57\u6BB5
|
|
227
243
|
export default ${JSON.stringify(rest, null, 2)}
|
|
228
244
|
`;
|
|
229
245
|
}
|
|
@@ -243,10 +259,39 @@ function createPagesPlugin(pluginOptions) {
|
|
|
243
259
|
dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
|
|
244
260
|
exclude: ["**/components/**/*.*"],
|
|
245
261
|
configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
|
|
262
|
+
onAfterMergePageMetaData: (ctx) => {
|
|
263
|
+
normalizePageNames(ctx);
|
|
264
|
+
},
|
|
246
265
|
...pluginOptions
|
|
247
266
|
});
|
|
248
267
|
return Array.isArray(result) ? result : [result];
|
|
249
268
|
}
|
|
269
|
+
function pathToPascalCase(path) {
|
|
270
|
+
if (!path) {
|
|
271
|
+
return "";
|
|
272
|
+
}
|
|
273
|
+
return path.split(/[/.-]/).filter(Boolean).map((str) => str.charAt(0).toUpperCase() + str.slice(1)).join("");
|
|
274
|
+
}
|
|
275
|
+
function normalizePageNames(pageContext) {
|
|
276
|
+
pageContext.pageMetaData.forEach((page) => {
|
|
277
|
+
if (page.name) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
page.name = pathToPascalCase(page.path);
|
|
281
|
+
});
|
|
282
|
+
pageContext.subPageMetaData.forEach((subPage) => {
|
|
283
|
+
subPage.pages.forEach((page) => {
|
|
284
|
+
if (subPage.root.startsWith(COMPONENTS_ASYNC_DIR_NAME)) {
|
|
285
|
+
page.layout = false;
|
|
286
|
+
}
|
|
287
|
+
if (page.name) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const fullPath = [subPage.root, page.path].filter(Boolean).join("/");
|
|
291
|
+
page.name = pathToPascalCase(fullPath);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
250
295
|
|
|
251
296
|
// src/plugins/context.ts
|
|
252
297
|
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
@@ -389,34 +434,113 @@ export default {}
|
|
|
389
434
|
};
|
|
390
435
|
|
|
391
436
|
// src/plugins/options.ts
|
|
437
|
+
var import_node_path5 = require("path");
|
|
392
438
|
var DEFAULT_DIRS = {
|
|
393
439
|
pages: "pages",
|
|
394
|
-
subPackages: [
|
|
440
|
+
subPackages: [],
|
|
395
441
|
layouts: "layouts"
|
|
396
442
|
};
|
|
397
443
|
var DEFAULT_IMPORTS = {
|
|
398
|
-
apis: ["vue", "uni-app", "composables/**", "
|
|
399
|
-
components: ["components
|
|
444
|
+
apis: ["vue", "uni-app", "composables/**", "store/**", "hooks/**", "constants/**"],
|
|
445
|
+
components: ["components", "components-biz"]
|
|
446
|
+
};
|
|
447
|
+
var DEFAULT_UNI_PRESET = {
|
|
448
|
+
attributify: false
|
|
400
449
|
};
|
|
401
|
-
function resolveOptions2(userOptions) {
|
|
450
|
+
function resolveOptions2(userOptions, root) {
|
|
402
451
|
const srcDir = userOptions.srcDir || "src";
|
|
452
|
+
const srcDirAbs = (0, import_node_path5.resolve)(root, srcDir);
|
|
453
|
+
const autoScanPackages = scanSubPackages(srcDirAbs, SUB_PACKAGE_DIR_NAME);
|
|
454
|
+
const autoScanCompAsyncPackages = scanSubPackages(srcDirAbs, COMPONENTS_ASYNC_DIR_NAME);
|
|
455
|
+
const userSubPackages = userOptions.dirs?.subPackages ?? [];
|
|
456
|
+
const subPackages = [...userSubPackages, ...autoScanPackages, ...autoScanCompAsyncPackages];
|
|
457
|
+
log(`autoScanPackages: ${JSON.stringify({ subPackages })}`);
|
|
403
458
|
const dirs = {
|
|
404
459
|
pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
|
|
405
|
-
subPackages
|
|
460
|
+
subPackages,
|
|
406
461
|
layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
|
|
407
462
|
};
|
|
408
463
|
const imports = {
|
|
409
464
|
apis: userOptions.imports?.apis ?? DEFAULT_IMPORTS.apis,
|
|
410
465
|
components: userOptions.imports?.components ?? DEFAULT_IMPORTS.components
|
|
411
466
|
};
|
|
467
|
+
const unocss = {
|
|
468
|
+
presetLegacyCompat: userOptions.unocss?.presetLegacyCompat ?? true,
|
|
469
|
+
uniPreset: userOptions.unocss?.uniPreset ?? DEFAULT_UNI_PRESET,
|
|
470
|
+
safelist: userOptions.unocss?.safelist ?? [],
|
|
471
|
+
themeColors: userOptions.unocss?.themeColors ?? {}
|
|
472
|
+
};
|
|
412
473
|
return {
|
|
413
474
|
srcDir,
|
|
414
475
|
dirs,
|
|
476
|
+
unocss,
|
|
415
477
|
imports,
|
|
416
478
|
overrides: userOptions.overrides
|
|
417
479
|
};
|
|
418
480
|
}
|
|
419
481
|
|
|
482
|
+
// src/plugins/unocss.ts
|
|
483
|
+
var import_unocss_preset_uni = require("@uni-helper/unocss-preset-uni");
|
|
484
|
+
var import_preset_legacy_compat = __toESM(require("@unocss/preset-legacy-compat"), 1);
|
|
485
|
+
var import_unocss = require("unocss");
|
|
486
|
+
var import_vite2 = __toESM(require("unocss/vite"), 1);
|
|
487
|
+
function presetUniva(userOptions) {
|
|
488
|
+
const presets = [];
|
|
489
|
+
if (userOptions.presetLegacyCompat) {
|
|
490
|
+
presets.push((0, import_preset_legacy_compat.default)({
|
|
491
|
+
commaStyleColorFunction: true,
|
|
492
|
+
legacyColorSpace: true
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
name: `${ID}-preset`,
|
|
497
|
+
presets: [
|
|
498
|
+
(0, import_unocss_preset_uni.presetUni)(userOptions.uniPreset),
|
|
499
|
+
(0, import_unocss.presetIcons)({
|
|
500
|
+
scale: 1.2,
|
|
501
|
+
warn: true,
|
|
502
|
+
extraProperties: {
|
|
503
|
+
"display": "inline-block",
|
|
504
|
+
"vertical-align": "middle"
|
|
505
|
+
}
|
|
506
|
+
}),
|
|
507
|
+
...presets
|
|
508
|
+
],
|
|
509
|
+
shortcuts: [
|
|
510
|
+
["border-s", "border border-solid"],
|
|
511
|
+
["wh-full", "w-full h-full"],
|
|
512
|
+
["f-c-c", "flex justify-center items-center"],
|
|
513
|
+
["f-col-c", "flex-col justify-center items-center"],
|
|
514
|
+
["flex-items", "flex items-center"],
|
|
515
|
+
["flex-justify", "flex justify-center"],
|
|
516
|
+
["flex-col", "flex flex-col"]
|
|
517
|
+
],
|
|
518
|
+
transformers: [(0, import_unocss.transformerDirectives)(), (0, import_unocss.transformerVariantGroup)()],
|
|
519
|
+
rules: [
|
|
520
|
+
[
|
|
521
|
+
"p-safe",
|
|
522
|
+
{
|
|
523
|
+
padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
|
|
524
|
+
}
|
|
525
|
+
],
|
|
526
|
+
["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
|
|
527
|
+
["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
|
|
528
|
+
],
|
|
529
|
+
safelist: userOptions.safelist,
|
|
530
|
+
theme: {
|
|
531
|
+
colors: userOptions.themeColors
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
function createUnocssPlugin(univaOptions, unocssOptions = {}) {
|
|
536
|
+
return (0, import_vite2.default)({
|
|
537
|
+
presets: [
|
|
538
|
+
presetUniva(univaOptions)
|
|
539
|
+
],
|
|
540
|
+
...unocssOptions
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
420
544
|
// src/plugins/index.ts
|
|
421
545
|
var context;
|
|
422
546
|
function createCorePlugin() {
|
|
@@ -475,7 +599,7 @@ function createUnivaPlugins(resolved) {
|
|
|
475
599
|
enabledGlobalRef: true,
|
|
476
600
|
rootFileName: ROOT_NAME,
|
|
477
601
|
excludePages: [
|
|
478
|
-
|
|
602
|
+
`${COMPONENTS_ASYNC_DIR_NAME}/**/*.*`
|
|
479
603
|
],
|
|
480
604
|
...resolved.overrides?.root
|
|
481
605
|
}));
|
|
@@ -490,7 +614,13 @@ function createUnivaPlugins(resolved) {
|
|
|
490
614
|
...resolved.overrides?.manifest
|
|
491
615
|
}));
|
|
492
616
|
plugins.push(...(0, import_plugin_uni.default)());
|
|
493
|
-
plugins.push(
|
|
617
|
+
plugins.push((0, import_vite_plugin_uni_polyfill.default)());
|
|
618
|
+
plugins.push(createUnocssPlugin(resolved.unocss, resolved.overrides?.unocss));
|
|
619
|
+
plugins.push((0, import_bundle_optimizer.default)({
|
|
620
|
+
enable: true,
|
|
621
|
+
logger: resolved.debug,
|
|
622
|
+
...resolved.overrides?.optimization
|
|
623
|
+
}));
|
|
494
624
|
const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
|
|
495
625
|
const autoImportPlugin = (0, import_vite3.default)({
|
|
496
626
|
imports: presets,
|
|
@@ -513,14 +643,14 @@ function Univa() {
|
|
|
513
643
|
context.loadUserConfigSync();
|
|
514
644
|
setDebug(context.config?.debug ?? false);
|
|
515
645
|
context.ensureRootComponent(`${ROOT_NAME}.vue`);
|
|
516
|
-
const resolved = resolveOptions2(context.config || {});
|
|
646
|
+
const resolved = resolveOptions2(context.config || {}, context.root);
|
|
517
647
|
log("\u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
|
|
518
648
|
return createUnivaPlugins(resolved);
|
|
519
649
|
}
|
|
520
650
|
var plugins_default = Univa;
|
|
521
651
|
|
|
522
652
|
// src/index.ts
|
|
523
|
-
var
|
|
653
|
+
var import_unocss_preset_uni2 = require("@uni-helper/unocss-preset-uni");
|
|
524
654
|
var import_vite_plugin_uni_components2 = require("@uni-helper/vite-plugin-uni-components");
|
|
525
655
|
var import_vite_plugin_uni_components3 = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
|
|
526
656
|
var import_vite_plugin_uni_layouts2 = require("@uni-helper/vite-plugin-uni-layouts");
|
|
@@ -530,7 +660,6 @@ var import_vite4 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
|
530
660
|
// Annotate the CommonJS export names for ESM import in node:
|
|
531
661
|
0 && (module.exports = {
|
|
532
662
|
AutoImport,
|
|
533
|
-
PageContext,
|
|
534
663
|
UniKuRoot,
|
|
535
664
|
Univa,
|
|
536
665
|
VitePluginUniComponents,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { PagesConfig } from '@uni-helper/uni-pages-types';
|
|
2
2
|
export { Condition, EasyCom, GlobalStyle, PageMetaDatum, PagesConfig, SubPackage, TabBar, TabBarItem } from '@uni-helper/uni-pages-types';
|
|
3
|
+
import { UserUniPresetOptions } from '@uni-helper/unocss-preset-uni';
|
|
4
|
+
export { UserUniPresetOptions, presetUni } from '@uni-helper/unocss-preset-uni';
|
|
3
5
|
import { Options } from '@uni-helper/vite-plugin-uni-components';
|
|
4
6
|
export { ComponentInfo, ComponentResolver, Options as ComponentsOptions, ResolvedOptions as ComponentsResolvedOptions, ImportInfo, default as VitePluginUniComponents, camelCase, kebabCase, pascalCase } from '@uni-helper/vite-plugin-uni-components';
|
|
5
7
|
import { UserManifestConfig } from '@uni-helper/vite-plugin-uni-manifest';
|
|
6
8
|
import { UserOptions } from '@uni-helper/vite-plugin-uni-pages';
|
|
7
9
|
export { PageContext, PagePath, UserOptions as PagesPluginOptions, ResolvedOptions as PagesResolvedOptions, SubPageMetaDatum, VitePluginUniPages, definePage } from '@uni-helper/vite-plugin-uni-pages';
|
|
10
|
+
import { OptimizationOptions } from '@uni-ku/bundle-optimizer';
|
|
11
|
+
import { ConfigBase } from 'unocss';
|
|
12
|
+
export { ConfigBase as UnoCSSConfigBase } from 'unocss';
|
|
8
13
|
import { Options as Options$1 } from 'unplugin-auto-import/types';
|
|
9
14
|
export { Options as AutoImportOptions } from 'unplugin-auto-import/types';
|
|
10
15
|
import { PluginOption } from 'vite';
|
|
11
|
-
export { presetUni } from '@uni-helper/unocss-preset-uni';
|
|
12
16
|
export { VitePluginUniLayouts } from '@uni-helper/vite-plugin-uni-layouts';
|
|
13
17
|
export { default as UniKuRoot } from '@uni-ku/root';
|
|
14
18
|
export { default as AutoImport } from 'unplugin-auto-import/vite';
|
|
@@ -58,6 +62,13 @@ interface UnivaDirs {
|
|
|
58
62
|
/** 布局目录,默认 'layouts' */
|
|
59
63
|
layouts?: string;
|
|
60
64
|
}
|
|
65
|
+
interface UnivaUnocss {
|
|
66
|
+
/** 是否开启兼容模式,默认 false */
|
|
67
|
+
presetLegacyCompat?: boolean;
|
|
68
|
+
uniPreset?: UserUniPresetOptions;
|
|
69
|
+
safelist?: string[];
|
|
70
|
+
themeColors?: Record<string, string>;
|
|
71
|
+
}
|
|
61
72
|
/**
|
|
62
73
|
* 自动导入配置
|
|
63
74
|
*/
|
|
@@ -91,6 +102,12 @@ interface ResolvedUnivaDirs {
|
|
|
91
102
|
subPackages: string[];
|
|
92
103
|
layouts: string;
|
|
93
104
|
}
|
|
105
|
+
interface ResolvedUnivaUnocss {
|
|
106
|
+
presetLegacyCompat: boolean;
|
|
107
|
+
uniPreset: UserUniPresetOptions;
|
|
108
|
+
safelist: string[];
|
|
109
|
+
themeColors: Record<string, string>;
|
|
110
|
+
}
|
|
94
111
|
/**
|
|
95
112
|
* 解析后的自动导入配置(字段必填,已应用默认值)
|
|
96
113
|
*/
|
|
@@ -118,10 +135,7 @@ interface RootOptions {
|
|
|
118
135
|
/**
|
|
119
136
|
* UnoCSS 模块底层选项(用于 overrides)
|
|
120
137
|
*/
|
|
121
|
-
interface UnoCSSOptions {
|
|
122
|
-
presets?: unknown[];
|
|
123
|
-
rules?: unknown[];
|
|
124
|
-
shortcuts?: Record<string, string | string[]>;
|
|
138
|
+
interface UnoCSSOptions extends ConfigBase {
|
|
125
139
|
}
|
|
126
140
|
/**
|
|
127
141
|
* 底层插件逃生口
|
|
@@ -144,6 +158,8 @@ interface UnivaOverrides {
|
|
|
144
158
|
unocss?: UnoCSSOptions;
|
|
145
159
|
/** @uni-helper/vite-plugin-uni-manifest 完整选项 */
|
|
146
160
|
manifest?: UserManifestOptions;
|
|
161
|
+
/** @uni-ku/bundle-optimizer 完整选项 */
|
|
162
|
+
optimization?: OptimizationOptions;
|
|
147
163
|
}
|
|
148
164
|
/**
|
|
149
165
|
* Univa 统一配置接口(工程级约定)
|
|
@@ -170,6 +186,7 @@ interface UnivaOptions {
|
|
|
170
186
|
pages?: Partial<PagesConfig>;
|
|
171
187
|
/** 应用级 manifest.json 配置 */
|
|
172
188
|
manifest?: Partial<UserManifestConfig>;
|
|
189
|
+
unocss?: UnivaUnocss;
|
|
173
190
|
/** 底层插件逃生口(覆盖融合层默认,高级用户使用) */
|
|
174
191
|
overrides?: UnivaOverrides;
|
|
175
192
|
}
|
|
@@ -186,6 +203,7 @@ interface ResolvedOptions extends Omit<UnivaOptions, 'dirs' | 'imports' | 'srcDi
|
|
|
186
203
|
dirs: ResolvedUnivaDirs;
|
|
187
204
|
/** 自动导入配置(已应用默认值,字段必填) */
|
|
188
205
|
imports: ResolvedUnivaImports;
|
|
206
|
+
unocss: ResolvedUnivaUnocss;
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
/**
|
|
@@ -219,4 +237,4 @@ declare function createUnivaPlugins(resolved: ResolvedOptions): PluginOption[];
|
|
|
219
237
|
*/
|
|
220
238
|
declare function Univa(): PluginOption[];
|
|
221
239
|
|
|
222
|
-
export { type LayoutsOptions, type ResolvedOptions, type ResolvedUnivaDirs, type ResolvedUnivaImports, type RootOptions, Univa, type UnivaDirs, type UnivaImports, type UnivaOptions, type UnivaOverrides, type UnoCSSOptions, createUnivaPlugins, defineConfig };
|
|
240
|
+
export { type LayoutsOptions, type ResolvedOptions, type ResolvedUnivaDirs, type ResolvedUnivaImports, type ResolvedUnivaUnocss, type RootOptions, Univa, type UnivaDirs, type UnivaImports, type UnivaOptions, type UnivaOverrides, type UnivaUnocss, type UnoCSSOptions, createUnivaPlugins, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { PagesConfig } from '@uni-helper/uni-pages-types';
|
|
2
2
|
export { Condition, EasyCom, GlobalStyle, PageMetaDatum, PagesConfig, SubPackage, TabBar, TabBarItem } from '@uni-helper/uni-pages-types';
|
|
3
|
+
import { UserUniPresetOptions } from '@uni-helper/unocss-preset-uni';
|
|
4
|
+
export { UserUniPresetOptions, presetUni } from '@uni-helper/unocss-preset-uni';
|
|
3
5
|
import { Options } from '@uni-helper/vite-plugin-uni-components';
|
|
4
6
|
export { ComponentInfo, ComponentResolver, Options as ComponentsOptions, ResolvedOptions as ComponentsResolvedOptions, ImportInfo, default as VitePluginUniComponents, camelCase, kebabCase, pascalCase } from '@uni-helper/vite-plugin-uni-components';
|
|
5
7
|
import { UserManifestConfig } from '@uni-helper/vite-plugin-uni-manifest';
|
|
6
8
|
import { UserOptions } from '@uni-helper/vite-plugin-uni-pages';
|
|
7
9
|
export { PageContext, PagePath, UserOptions as PagesPluginOptions, ResolvedOptions as PagesResolvedOptions, SubPageMetaDatum, VitePluginUniPages, definePage } from '@uni-helper/vite-plugin-uni-pages';
|
|
10
|
+
import { OptimizationOptions } from '@uni-ku/bundle-optimizer';
|
|
11
|
+
import { ConfigBase } from 'unocss';
|
|
12
|
+
export { ConfigBase as UnoCSSConfigBase } from 'unocss';
|
|
8
13
|
import { Options as Options$1 } from 'unplugin-auto-import/types';
|
|
9
14
|
export { Options as AutoImportOptions } from 'unplugin-auto-import/types';
|
|
10
15
|
import { PluginOption } from 'vite';
|
|
11
|
-
export { presetUni } from '@uni-helper/unocss-preset-uni';
|
|
12
16
|
export { VitePluginUniLayouts } from '@uni-helper/vite-plugin-uni-layouts';
|
|
13
17
|
export { default as UniKuRoot } from '@uni-ku/root';
|
|
14
18
|
export { default as AutoImport } from 'unplugin-auto-import/vite';
|
|
@@ -58,6 +62,13 @@ interface UnivaDirs {
|
|
|
58
62
|
/** 布局目录,默认 'layouts' */
|
|
59
63
|
layouts?: string;
|
|
60
64
|
}
|
|
65
|
+
interface UnivaUnocss {
|
|
66
|
+
/** 是否开启兼容模式,默认 false */
|
|
67
|
+
presetLegacyCompat?: boolean;
|
|
68
|
+
uniPreset?: UserUniPresetOptions;
|
|
69
|
+
safelist?: string[];
|
|
70
|
+
themeColors?: Record<string, string>;
|
|
71
|
+
}
|
|
61
72
|
/**
|
|
62
73
|
* 自动导入配置
|
|
63
74
|
*/
|
|
@@ -91,6 +102,12 @@ interface ResolvedUnivaDirs {
|
|
|
91
102
|
subPackages: string[];
|
|
92
103
|
layouts: string;
|
|
93
104
|
}
|
|
105
|
+
interface ResolvedUnivaUnocss {
|
|
106
|
+
presetLegacyCompat: boolean;
|
|
107
|
+
uniPreset: UserUniPresetOptions;
|
|
108
|
+
safelist: string[];
|
|
109
|
+
themeColors: Record<string, string>;
|
|
110
|
+
}
|
|
94
111
|
/**
|
|
95
112
|
* 解析后的自动导入配置(字段必填,已应用默认值)
|
|
96
113
|
*/
|
|
@@ -118,10 +135,7 @@ interface RootOptions {
|
|
|
118
135
|
/**
|
|
119
136
|
* UnoCSS 模块底层选项(用于 overrides)
|
|
120
137
|
*/
|
|
121
|
-
interface UnoCSSOptions {
|
|
122
|
-
presets?: unknown[];
|
|
123
|
-
rules?: unknown[];
|
|
124
|
-
shortcuts?: Record<string, string | string[]>;
|
|
138
|
+
interface UnoCSSOptions extends ConfigBase {
|
|
125
139
|
}
|
|
126
140
|
/**
|
|
127
141
|
* 底层插件逃生口
|
|
@@ -144,6 +158,8 @@ interface UnivaOverrides {
|
|
|
144
158
|
unocss?: UnoCSSOptions;
|
|
145
159
|
/** @uni-helper/vite-plugin-uni-manifest 完整选项 */
|
|
146
160
|
manifest?: UserManifestOptions;
|
|
161
|
+
/** @uni-ku/bundle-optimizer 完整选项 */
|
|
162
|
+
optimization?: OptimizationOptions;
|
|
147
163
|
}
|
|
148
164
|
/**
|
|
149
165
|
* Univa 统一配置接口(工程级约定)
|
|
@@ -170,6 +186,7 @@ interface UnivaOptions {
|
|
|
170
186
|
pages?: Partial<PagesConfig>;
|
|
171
187
|
/** 应用级 manifest.json 配置 */
|
|
172
188
|
manifest?: Partial<UserManifestConfig>;
|
|
189
|
+
unocss?: UnivaUnocss;
|
|
173
190
|
/** 底层插件逃生口(覆盖融合层默认,高级用户使用) */
|
|
174
191
|
overrides?: UnivaOverrides;
|
|
175
192
|
}
|
|
@@ -186,6 +203,7 @@ interface ResolvedOptions extends Omit<UnivaOptions, 'dirs' | 'imports' | 'srcDi
|
|
|
186
203
|
dirs: ResolvedUnivaDirs;
|
|
187
204
|
/** 自动导入配置(已应用默认值,字段必填) */
|
|
188
205
|
imports: ResolvedUnivaImports;
|
|
206
|
+
unocss: ResolvedUnivaUnocss;
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
/**
|
|
@@ -219,4 +237,4 @@ declare function createUnivaPlugins(resolved: ResolvedOptions): PluginOption[];
|
|
|
219
237
|
*/
|
|
220
238
|
declare function Univa(): PluginOption[];
|
|
221
239
|
|
|
222
|
-
export { type LayoutsOptions, type ResolvedOptions, type ResolvedUnivaDirs, type ResolvedUnivaImports, type RootOptions, Univa, type UnivaDirs, type UnivaImports, type UnivaOptions, type UnivaOverrides, type UnoCSSOptions, createUnivaPlugins, defineConfig };
|
|
240
|
+
export { type LayoutsOptions, type ResolvedOptions, type ResolvedUnivaDirs, type ResolvedUnivaImports, type ResolvedUnivaUnocss, type RootOptions, Univa, type UnivaDirs, type UnivaImports, type UnivaOptions, type UnivaOverrides, type UnivaUnocss, type UnoCSSOptions, createUnivaPlugins, defineConfig };
|
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",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@uni-helper/vite-plugin-uni-layouts": "0.1.11",
|
|
75
75
|
"@uni-helper/vite-plugin-uni-manifest": "0.4.1",
|
|
76
76
|
"@uni-helper/vite-plugin-uni-pages": "0.4.6",
|
|
77
|
+
"@uni-ku/bundle-optimizer": "2.2.0",
|
|
77
78
|
"@uni-ku/root": "1.4.1",
|
|
78
79
|
"@unocss/eslint-plugin": "66.6.7",
|
|
79
80
|
"@unocss/preset-legacy-compat": "66.0.0",
|