@univa/core 0.0.5 → 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/README.md +333 -218
- package/dist/index.cjs +331 -295
- package/dist/index.d.cts +176 -27
- package/dist/index.d.ts +176 -27
- package/dist/index.js +319 -293
- package/package.json +30 -29
- package/dist/hooks.cjs +0 -83
- package/dist/hooks.d.cts +0 -36
- package/dist/hooks.d.ts +0 -36
- package/dist/hooks.js +0 -56
- package/src/client.d.ts +0 -12
- package/src/global.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -30,343 +30,379 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
AutoImport: () => import_vite3.default,
|
|
34
|
+
PageContext: () => import_vite_plugin_uni_pages2.PageContext,
|
|
35
|
+
UniKuRoot: () => import_root2.default,
|
|
36
|
+
Univa: () => plugins_default,
|
|
37
|
+
VitePluginUniComponents: () => import_vite_plugin_uni_components3.default,
|
|
38
|
+
VitePluginUniLayouts: () => import_vite_plugin_uni_layouts2.VitePluginUniLayouts,
|
|
39
|
+
VitePluginUniPages: () => import_vite_plugin_uni_pages2.VitePluginUniPages,
|
|
40
|
+
camelCase: () => import_vite_plugin_uni_components2.camelCase,
|
|
41
|
+
createUnivaPlugins: () => createUnivaPlugins,
|
|
42
|
+
defineConfig: () => defineConfig,
|
|
43
|
+
kebabCase: () => import_vite_plugin_uni_components2.kebabCase,
|
|
44
|
+
pascalCase: () => import_vite_plugin_uni_components2.pascalCase,
|
|
45
|
+
presetUni: () => import_unocss_preset_uni.presetUni
|
|
36
46
|
});
|
|
37
47
|
module.exports = __toCommonJS(index_exports);
|
|
38
48
|
|
|
49
|
+
// src/config/index.ts
|
|
50
|
+
function defineConfig(config) {
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
// src/plugins/index.ts
|
|
40
55
|
var import_plugin_uni = __toESM(require("@uni-helper/plugin-uni"), 1);
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var import_root = __toESM(require("@
|
|
44
|
-
var
|
|
56
|
+
var import_vite_plugin_uni_components = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
|
|
57
|
+
var import_vite_plugin_uni_layouts = require("@uni-helper/vite-plugin-uni-layouts");
|
|
58
|
+
var import_root = __toESM(require("@uni-ku/root"), 1);
|
|
59
|
+
var import_vite = __toESM(require("unocss/vite"), 1);
|
|
60
|
+
var import_vite2 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
45
61
|
|
|
46
62
|
// src/constant.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
63
|
+
var ID = "univa";
|
|
64
|
+
var UNIVA_DIR_NAME = `.${ID}`;
|
|
49
65
|
|
|
50
|
-
// src/
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"pinia",
|
|
57
|
-
"uni-app",
|
|
58
|
-
{
|
|
59
|
-
from: "@univa/core/hooks",
|
|
60
|
-
imports: ["usePageContext"]
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
dirs: [
|
|
64
|
-
"src/hooks/**",
|
|
65
|
-
"!src/hooks/**/_*/**",
|
|
66
|
-
"src/store/**",
|
|
67
|
-
"!src/store/**/_*/**",
|
|
68
|
-
"src/constants/**"
|
|
69
|
-
],
|
|
70
|
-
vueTemplate: true,
|
|
71
|
-
dts: `${DTS_DIR}/auto-imports.d.ts`
|
|
72
|
-
};
|
|
73
|
-
const userAutoImportOptions = typeof options.autoImport === "object" ? options.autoImport : {};
|
|
74
|
-
const mergedOptions = {
|
|
75
|
-
...defaultAutoImportOptions,
|
|
76
|
-
...userAutoImportOptions
|
|
77
|
-
};
|
|
78
|
-
if (userAutoImportOptions.imports) {
|
|
79
|
-
const userImports = Array.isArray(userAutoImportOptions.imports) ? userAutoImportOptions.imports : [userAutoImportOptions.imports];
|
|
80
|
-
mergedOptions.imports = [...defaultAutoImportOptions.imports, ...userImports];
|
|
66
|
+
// src/utils/fs.ts
|
|
67
|
+
var import_node_fs = require("fs");
|
|
68
|
+
var import_node_path = require("path");
|
|
69
|
+
function ensureDir(dir) {
|
|
70
|
+
if (!(0, import_node_fs.existsSync)(dir)) {
|
|
71
|
+
(0, import_node_fs.mkdirSync)(dir, { recursive: true });
|
|
81
72
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
}
|
|
74
|
+
function getUnivaDir(cwd) {
|
|
75
|
+
return (0, import_node_path.join)(cwd, UNIVA_DIR_NAME);
|
|
76
|
+
}
|
|
77
|
+
function ensureUnivaDir(cwd) {
|
|
78
|
+
const dir = getUnivaDir(cwd);
|
|
79
|
+
ensureDir(dir);
|
|
80
|
+
return dir;
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
// src/plugins/
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...userComponentsOptions
|
|
103
|
-
};
|
|
104
|
-
if (userComponentsOptions.dirs) {
|
|
105
|
-
const userDirs = Array.isArray(userComponentsOptions.dirs) ? userComponentsOptions.dirs : [userComponentsOptions.dirs];
|
|
106
|
-
mergedOptions.dirs = [...defaultComponentsOptions.dirs, ...userDirs];
|
|
107
|
-
}
|
|
108
|
-
if (userComponentsOptions.exclude) {
|
|
109
|
-
const userExclude = Array.isArray(userComponentsOptions.exclude) ? userComponentsOptions.exclude : [userComponentsOptions.exclude];
|
|
110
|
-
mergedOptions.exclude = [...defaultComponentsOptions.exclude, ...userExclude];
|
|
111
|
-
}
|
|
112
|
-
if (userComponentsOptions.globalNamespaces) {
|
|
113
|
-
const userGlobalNamespaces = Array.isArray(userComponentsOptions.globalNamespaces) ? userComponentsOptions.globalNamespaces : [userComponentsOptions.globalNamespaces];
|
|
114
|
-
mergedOptions.globalNamespaces = [...defaultComponentsOptions.globalNamespaces, ...userGlobalNamespaces];
|
|
83
|
+
// src/plugins/context.ts
|
|
84
|
+
var import_node_fs3 = require("fs");
|
|
85
|
+
var import_node_path3 = require("path");
|
|
86
|
+
var import_utils = require("@antfu/utils");
|
|
87
|
+
var import_c12 = require("c12");
|
|
88
|
+
var import_jiti = require("jiti");
|
|
89
|
+
|
|
90
|
+
// src/utils/merge.ts
|
|
91
|
+
var import_defu = require("defu");
|
|
92
|
+
var mergeWithArrayOverride = (0, import_defu.createDefu)((originObj, key, updates) => {
|
|
93
|
+
if (Array.isArray(originObj[key]) && Array.isArray(updates)) {
|
|
94
|
+
originObj[key] = updates;
|
|
95
|
+
return true;
|
|
115
96
|
}
|
|
116
|
-
|
|
117
|
-
}
|
|
97
|
+
});
|
|
118
98
|
|
|
119
|
-
// src/plugins/
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
99
|
+
// src/plugins/pages.ts
|
|
100
|
+
var import_node_fs2 = require("fs");
|
|
101
|
+
var import_node_path2 = require("path");
|
|
102
|
+
var import_vite_plugin_uni_pages = require("@uni-helper/vite-plugin-uni-pages");
|
|
103
|
+
function getPagesConfigPath(root) {
|
|
104
|
+
return (0, import_node_path2.join)(getUnivaDir(root), "pages-config.ts");
|
|
105
|
+
}
|
|
106
|
+
function generatePagesConfigContent(content) {
|
|
107
|
+
const { pages, subPackages, ...rest } = content;
|
|
108
|
+
void pages;
|
|
109
|
+
void subPackages;
|
|
110
|
+
return `// Auto-generated by @univa/core
|
|
111
|
+
// \u6765\u6E90\uFF1Auniva.config.ts \u7684 pages \u5B57\u6BB5
|
|
112
|
+
export default ${JSON.stringify(rest, null, 2)}
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
function generatePagesConfigFile(content, root) {
|
|
116
|
+
const pagesConfigPath = getPagesConfigPath(root);
|
|
117
|
+
const newContent = generatePagesConfigContent(content);
|
|
118
|
+
if ((0, import_node_fs2.existsSync)(pagesConfigPath)) {
|
|
119
|
+
const existingContent = (0, import_node_fs2.readFileSync)(pagesConfigPath, "utf-8");
|
|
120
|
+
if (existingContent === newContent) {
|
|
121
|
+
return;
|
|
125
122
|
}
|
|
123
|
+
}
|
|
124
|
+
(0, import_node_fs2.writeFileSync)(pagesConfigPath, newContent, "utf-8");
|
|
125
|
+
}
|
|
126
|
+
function createPagesPlugin(pluginOptions) {
|
|
127
|
+
const result = (0, import_vite_plugin_uni_pages.VitePluginUniPages)({
|
|
128
|
+
dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
|
|
129
|
+
exclude: ["**/components/**/*.*"],
|
|
130
|
+
configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
|
|
131
|
+
...pluginOptions
|
|
126
132
|
});
|
|
133
|
+
return Array.isArray(result) ? result : [result];
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
// src/plugins/
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return prefix + toPascalCase(parts);
|
|
136
|
+
// src/plugins/context.ts
|
|
137
|
+
var DEFAULT_ROOT_FILE_NAME = "App.ku.vue";
|
|
138
|
+
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
139
|
+
<!-- UniKuRoot \u865A\u62DF\u6839\u7EC4\u4EF6\uFF0C\u53EF\u5728\u6B64\u6DFB\u52A0\u5168\u5C40\u7EC4\u4EF6\uFF08\u5982 Toast\u3001ConfigProvider \u7B49\uFF09 -->
|
|
140
|
+
<template>
|
|
141
|
+
<KuRootView />
|
|
142
|
+
</template>
|
|
143
|
+
`;
|
|
144
|
+
function ensureRootComponent(config, root) {
|
|
145
|
+
const srcDir = config?.srcDir || "src";
|
|
146
|
+
const rootFileName = config?.overrides?.root?.rootFileName || DEFAULT_ROOT_FILE_NAME;
|
|
147
|
+
const rootComponentPath = (0, import_node_path3.join)(root, srcDir, rootFileName);
|
|
148
|
+
if ((0, import_node_fs3.existsSync)(rootComponentPath)) {
|
|
149
|
+
return;
|
|
144
150
|
}
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
(0, import_node_fs3.writeFileSync)(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
|
|
152
|
+
console.log(`[univa] \u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${(0, import_utils.slash)(rootComponentPath)}`);
|
|
147
153
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
var UnivaContext = class {
|
|
155
|
+
_server;
|
|
156
|
+
config;
|
|
157
|
+
configPath;
|
|
158
|
+
root;
|
|
159
|
+
constructor(options) {
|
|
160
|
+
this.root = options.root;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 同步加载用户配置(univa.config.ts)
|
|
164
|
+
*/
|
|
165
|
+
loadUserConfigSync() {
|
|
166
|
+
const jiti = (0, import_jiti.createJiti)(this.root);
|
|
167
|
+
const configFile = (0, import_node_path3.join)(this.root, `${ID}.config`);
|
|
168
|
+
try {
|
|
169
|
+
const configModule = jiti(configFile);
|
|
170
|
+
const userConfig = configModule?.default || configModule;
|
|
171
|
+
this.config = mergeWithArrayOverride({}, userConfig);
|
|
172
|
+
this.configPath = jiti.resolve(configFile);
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 异步加载用户配置(c12 支持更多格式与合并能力)
|
|
178
|
+
*/
|
|
179
|
+
async loadUserConfigAsync() {
|
|
180
|
+
const { config: userConfig, configFile } = await (0, import_c12.loadConfig)({
|
|
181
|
+
name: ID,
|
|
182
|
+
cwd: this.root,
|
|
183
|
+
defaults: this.config || {},
|
|
184
|
+
merger: mergeWithArrayOverride
|
|
185
|
+
});
|
|
186
|
+
this.config = userConfig;
|
|
187
|
+
this.configPath = configFile || "";
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 设置 Vite 开发服务器
|
|
191
|
+
*/
|
|
192
|
+
setupViteServer(server) {
|
|
193
|
+
if (this._server === server)
|
|
194
|
+
return;
|
|
195
|
+
this._server = server;
|
|
196
|
+
this.setupWatcher(server.watcher);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 设置文件监听器
|
|
200
|
+
*
|
|
201
|
+
* 监听 univa.config.ts 变化,重新生成 .univa/pages.ts
|
|
202
|
+
*/
|
|
203
|
+
setupWatcher(watcher) {
|
|
204
|
+
if (!this.configPath) {
|
|
151
205
|
return;
|
|
152
206
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
subPackage.pages.forEach((page) => {
|
|
159
|
-
if (page.name) {
|
|
207
|
+
watcher.add(this.configPath);
|
|
208
|
+
watcher.on("change", async (filePath) => {
|
|
209
|
+
filePath = (0, import_utils.slash)(filePath);
|
|
210
|
+
const configPath = (0, import_utils.slash)(this.configPath || "");
|
|
211
|
+
if (filePath !== configPath) {
|
|
160
212
|
return;
|
|
161
213
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (isAsyncComponent) {
|
|
167
|
-
page.layout = false;
|
|
168
|
-
}
|
|
169
|
-
page.name = _pathToName(`${root}/${page.path}`, "pages-sub", "Sub");
|
|
214
|
+
await this.updateConfig();
|
|
215
|
+
this.onUpdate();
|
|
170
216
|
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function resolveUserPagesConfig(config) {
|
|
174
|
-
if (!config.tabBar) {
|
|
175
|
-
return config;
|
|
176
217
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (tabBar.list && tabBar.list.length > 0) {
|
|
181
|
-
tabBar.list = tabBar.list.map((item) => {
|
|
182
|
-
const filtered = { ...item };
|
|
183
|
-
filtered.customIconPath = filtered.iconPath;
|
|
184
|
-
filtered.customSelectedIconPath = filtered.selectedIconPath;
|
|
185
|
-
if (!filtered.iconPath?.startsWith("static/")) {
|
|
186
|
-
delete filtered.iconPath;
|
|
187
|
-
}
|
|
188
|
-
if (!filtered.selectedIconPath?.startsWith("static/")) {
|
|
189
|
-
delete filtered.selectedIconPath;
|
|
190
|
-
}
|
|
191
|
-
return filtered;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
218
|
+
async updateConfig() {
|
|
219
|
+
await this.loadUserConfigAsync();
|
|
220
|
+
this.updateGeneratedFiles();
|
|
194
221
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
222
|
+
/**
|
|
223
|
+
* 更新生成的文件
|
|
224
|
+
*
|
|
225
|
+
* 读取 univa.config.ts 的 pages 字段(应用级配置),
|
|
226
|
+
* 生成 .univa/pages.ts 供 VitePluginUniPages 消费。
|
|
227
|
+
* 同时确保 UniKuRoot 虚拟根组件文件存在。
|
|
228
|
+
*/
|
|
229
|
+
updateGeneratedFiles() {
|
|
230
|
+
const pagesConfig = this.config?.pages;
|
|
231
|
+
if (pagesConfig) {
|
|
232
|
+
generatePagesConfigFile(pagesConfig, this.root);
|
|
233
|
+
}
|
|
234
|
+
const pagesTsPath = getPagesConfigPath(this.root);
|
|
235
|
+
const emptyContent = `// Auto-generated by @univa/core
|
|
236
|
+
export default {}
|
|
237
|
+
`;
|
|
238
|
+
if (!(0, import_node_fs3.existsSync)(pagesTsPath)) {
|
|
239
|
+
(0, import_node_fs3.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
|
|
240
|
+
} else if (!pagesConfig) {
|
|
241
|
+
if ((0, import_node_fs3.readFileSync)(pagesTsPath, "utf-8") !== emptyContent) {
|
|
242
|
+
(0, import_node_fs3.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
|
|
217
243
|
}
|
|
218
|
-
}
|
|
219
|
-
(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
onAfterMergePageMetaData(ctx) {
|
|
235
|
-
processPageName(ctx);
|
|
236
|
-
const tabBar = ctx.pagesGlobConfig?.tabBar;
|
|
237
|
-
if (!tabBar) {
|
|
238
|
-
tabBarConfig = null;
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const clonedTabBar = { ...tabBar };
|
|
242
|
-
if (clonedTabBar.list) {
|
|
243
|
-
clonedTabBar.list = clonedTabBar.list.map((item) => {
|
|
244
|
-
const filtered = { ...item };
|
|
245
|
-
if (filtered.customIconPath) {
|
|
246
|
-
filtered.iconPath = filtered.customIconPath;
|
|
247
|
-
delete filtered.customIconPath;
|
|
248
|
-
}
|
|
249
|
-
if (filtered.customSelectedIconPath) {
|
|
250
|
-
filtered.selectedIconPath = filtered.customSelectedIconPath;
|
|
251
|
-
delete filtered.customSelectedIconPath;
|
|
252
|
-
}
|
|
253
|
-
return filtered;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
tabBarConfig = clonedTabBar;
|
|
257
|
-
},
|
|
258
|
-
dts: `${DTS_DIR}/uni-pages.d.ts`
|
|
259
|
-
})
|
|
260
|
-
];
|
|
261
|
-
}
|
|
262
|
-
function definePagesConfig(config) {
|
|
263
|
-
return config;
|
|
264
|
-
}
|
|
244
|
+
}
|
|
245
|
+
ensureRootComponent(this.config, this.root);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* 更新回调
|
|
249
|
+
* 触发 HMR
|
|
250
|
+
*/
|
|
251
|
+
onUpdate() {
|
|
252
|
+
if (!this._server) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this._server.ws.send({
|
|
256
|
+
type: "full-reload"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
};
|
|
265
260
|
|
|
266
|
-
// src/plugins/
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
// src/plugins/options.ts
|
|
262
|
+
var DEFAULT_DIRS = {
|
|
263
|
+
pages: "pages",
|
|
264
|
+
subPackages: ["pages-sub/*"],
|
|
265
|
+
layouts: "layouts"
|
|
266
|
+
};
|
|
267
|
+
var DEFAULT_IMPORTS = {
|
|
268
|
+
apis: ["vue", "uni-app", "composables/**", "stores/**", "hooks/**", "constants/**"],
|
|
269
|
+
components: ["components/**", "components-biz/**"]
|
|
270
|
+
};
|
|
271
|
+
function resolveOptions(userOptions) {
|
|
272
|
+
const srcDir = userOptions.srcDir || "src";
|
|
273
|
+
const dirs = {
|
|
274
|
+
pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
|
|
275
|
+
subPackages: userOptions.dirs?.subPackages ?? DEFAULT_DIRS.subPackages,
|
|
276
|
+
layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
|
|
277
|
+
};
|
|
278
|
+
const imports = {
|
|
279
|
+
apis: userOptions.imports?.apis ?? DEFAULT_IMPORTS.apis,
|
|
280
|
+
components: userOptions.imports?.components ?? DEFAULT_IMPORTS.components
|
|
281
|
+
};
|
|
279
282
|
return {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}),
|
|
285
|
-
(0, import_unocss.presetIcons)({
|
|
286
|
-
scale: 1.2,
|
|
287
|
-
warn: true,
|
|
288
|
-
extraProperties: {
|
|
289
|
-
"display": "inline-block",
|
|
290
|
-
"vertical-align": "middle"
|
|
291
|
-
}
|
|
292
|
-
}),
|
|
293
|
-
// 处理低端安卓机的样式问题,eg: `rgb(255 0 0)` -> `rgb(255, 0, 0)`
|
|
294
|
-
(0, import_preset_legacy_compat.default)({
|
|
295
|
-
commaStyleColorFunction: true,
|
|
296
|
-
legacyColorSpace: true
|
|
297
|
-
})
|
|
298
|
-
],
|
|
299
|
-
shortcuts: [
|
|
300
|
-
["border-s", "border border-solid"],
|
|
301
|
-
["wh-full", "w-full h-full"],
|
|
302
|
-
["f-c-c", "flex justify-center items-center"],
|
|
303
|
-
["f-col-c", "flex-col justify-center items-center"],
|
|
304
|
-
["flex-items", "flex items-center"],
|
|
305
|
-
["flex-justify", "flex justify-center"],
|
|
306
|
-
["flex-col", "flex flex-col"]
|
|
307
|
-
],
|
|
308
|
-
transformers: [
|
|
309
|
-
(0, import_unocss.transformerDirectives)(),
|
|
310
|
-
(0, import_unocss.transformerVariantGroup)()
|
|
311
|
-
],
|
|
312
|
-
rules: [
|
|
313
|
-
[
|
|
314
|
-
"p-safe",
|
|
315
|
-
{
|
|
316
|
-
padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
|
|
317
|
-
}
|
|
318
|
-
],
|
|
319
|
-
["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
|
|
320
|
-
["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
|
|
321
|
-
]
|
|
283
|
+
srcDir,
|
|
284
|
+
dirs,
|
|
285
|
+
imports,
|
|
286
|
+
overrides: userOptions.overrides
|
|
322
287
|
};
|
|
323
288
|
}
|
|
324
289
|
|
|
325
290
|
// src/plugins/index.ts
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
291
|
+
var context;
|
|
292
|
+
function createCorePlugin() {
|
|
293
|
+
return {
|
|
294
|
+
name: "vite-plugin-univa",
|
|
295
|
+
enforce: "pre",
|
|
296
|
+
async configResolved() {
|
|
297
|
+
await context.loadUserConfigAsync();
|
|
298
|
+
context.updateGeneratedFiles();
|
|
299
|
+
},
|
|
300
|
+
configureServer(server) {
|
|
301
|
+
context.setupViteServer(server);
|
|
336
302
|
}
|
|
337
303
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
304
|
+
}
|
|
305
|
+
function isPresetName(from) {
|
|
306
|
+
if (/[*?[\]{}]/.test(from))
|
|
307
|
+
return false;
|
|
308
|
+
if (/^@[\w.-]+\/[\w.-]+$/.test(from))
|
|
309
|
+
return true;
|
|
310
|
+
if (/[/\\]/.test(from))
|
|
311
|
+
return false;
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
function resolveApiSources(sources, srcDir) {
|
|
315
|
+
const presets = [];
|
|
316
|
+
const dirs = [];
|
|
317
|
+
for (const source of sources) {
|
|
318
|
+
if (typeof source !== "string") {
|
|
319
|
+
presets.push(source);
|
|
320
|
+
} else if (source.startsWith("!")) {
|
|
321
|
+
dirs.push(`!${srcDir}/${source.slice(1)}`);
|
|
322
|
+
} else if (isPresetName(source)) {
|
|
323
|
+
presets.push(source);
|
|
324
|
+
} else {
|
|
325
|
+
dirs.push(`${srcDir}/${source}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return { presets, dirs };
|
|
329
|
+
}
|
|
330
|
+
function createUnivaPlugins(resolved) {
|
|
331
|
+
const plugins = [];
|
|
332
|
+
const { srcDir } = resolved;
|
|
333
|
+
plugins.push(createCorePlugin());
|
|
334
|
+
plugins.push(...createPagesPlugin({
|
|
335
|
+
dir: `${srcDir}/${resolved.dirs.pages}`,
|
|
336
|
+
subPackages: resolved.dirs.subPackages.map((p) => `${srcDir}/${p}`),
|
|
337
|
+
...resolved.overrides?.pages
|
|
338
|
+
}));
|
|
339
|
+
plugins.push((0, import_vite_plugin_uni_layouts.VitePluginUniLayouts)({
|
|
340
|
+
layoutDir: `${srcDir}/${resolved.dirs.layouts}`,
|
|
341
|
+
...resolved.overrides?.layouts
|
|
342
|
+
}));
|
|
343
|
+
plugins.push((0, import_root.default)({
|
|
341
344
|
enabledGlobalRef: true,
|
|
342
|
-
autoCreateRoot: true,
|
|
343
345
|
excludePages: [
|
|
344
|
-
|
|
345
|
-
]
|
|
346
|
+
"components-async/**/*.*"
|
|
347
|
+
],
|
|
348
|
+
...resolved.overrides?.root
|
|
349
|
+
}));
|
|
350
|
+
plugins.push((0, import_vite_plugin_uni_components.default)({
|
|
351
|
+
dirs: resolved.imports.components.map((c) => `${srcDir}/${c}`),
|
|
352
|
+
dts: `${UNIVA_DIR_NAME}/components.d.ts`,
|
|
353
|
+
globalNamespaces: ["components", "common"],
|
|
354
|
+
directoryAsNamespace: true,
|
|
355
|
+
...resolved.overrides?.components
|
|
346
356
|
}));
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
357
|
+
plugins.push(...(0, import_plugin_uni.default)());
|
|
358
|
+
plugins.push(...(0, import_vite.default)());
|
|
359
|
+
const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
|
|
360
|
+
const autoImportPlugin = (0, import_vite2.default)({
|
|
361
|
+
imports: presets,
|
|
362
|
+
dirs,
|
|
363
|
+
dts: `${UNIVA_DIR_NAME}/auto-imports.d.ts`,
|
|
364
|
+
...resolved.overrides?.autoImport
|
|
365
|
+
});
|
|
366
|
+
if (Array.isArray(autoImportPlugin)) {
|
|
367
|
+
plugins.push(...autoImportPlugin);
|
|
368
|
+
} else {
|
|
369
|
+
plugins.push(autoImportPlugin);
|
|
370
|
+
}
|
|
371
|
+
return plugins;
|
|
355
372
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return createUnivaPlugins({
|
|
360
|
-
components: config?.components ?? true,
|
|
361
|
-
autoImport: config?.autoImport ?? true,
|
|
362
|
-
appRoot: config?.appRoot ?? true,
|
|
363
|
-
pages: config?.pages,
|
|
364
|
-
manifest: config?.manifest
|
|
373
|
+
function Univa() {
|
|
374
|
+
context = new UnivaContext({
|
|
375
|
+
root: process.cwd()
|
|
365
376
|
});
|
|
377
|
+
ensureUnivaDir(context.root);
|
|
378
|
+
context.loadUserConfigSync();
|
|
379
|
+
const resolved = resolveOptions(context.config || {});
|
|
380
|
+
console.log("[univa] \u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
|
|
381
|
+
return createUnivaPlugins(resolved);
|
|
366
382
|
}
|
|
383
|
+
var plugins_default = Univa;
|
|
384
|
+
|
|
385
|
+
// src/index.ts
|
|
386
|
+
var import_unocss_preset_uni = require("@uni-helper/unocss-preset-uni");
|
|
387
|
+
var import_vite_plugin_uni_components2 = require("@uni-helper/vite-plugin-uni-components");
|
|
388
|
+
var import_vite_plugin_uni_components3 = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
|
|
389
|
+
var import_vite_plugin_uni_layouts2 = require("@uni-helper/vite-plugin-uni-layouts");
|
|
390
|
+
var import_vite_plugin_uni_pages2 = require("@uni-helper/vite-plugin-uni-pages");
|
|
391
|
+
var import_root2 = __toESM(require("@uni-ku/root"), 1);
|
|
392
|
+
var import_vite3 = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
367
393
|
// Annotate the CommonJS export names for ESM import in node:
|
|
368
394
|
0 && (module.exports = {
|
|
395
|
+
AutoImport,
|
|
396
|
+
PageContext,
|
|
397
|
+
UniKuRoot,
|
|
369
398
|
Univa,
|
|
370
|
-
|
|
371
|
-
|
|
399
|
+
VitePluginUniComponents,
|
|
400
|
+
VitePluginUniLayouts,
|
|
401
|
+
VitePluginUniPages,
|
|
402
|
+
camelCase,
|
|
403
|
+
createUnivaPlugins,
|
|
404
|
+
defineConfig,
|
|
405
|
+
kebabCase,
|
|
406
|
+
pascalCase,
|
|
407
|
+
presetUni
|
|
372
408
|
});
|