@quiteer/vite 0.0.7 → 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/bin/qvite.mjs +116 -44
- package/dist/index.d.mts +12 -8
- package/dist/index.mjs +6 -5906
- package/package.json +4 -4
- package/dist/bin/context-Db5EuGKU-B3vpL0eS.mjs +0 -24
- package/dist/bin/dist-BmyFpZwL.mjs +0 -7
- package/dist/bin/dist-BniM_x9D.mjs +0 -5256
- package/dist/bin/dist-Bvgk2hb8.mjs +0 -187
- package/dist/bin/dist-CjNY_432.mjs +0 -473
- package/dist/bin/dist-DQNZhGEj.mjs +0 -10562
- package/dist/bin/esm-CQYKr9An.mjs +0 -1557
- package/dist/bin/experimental-index-DiVJ_oZg.mjs +0 -71
- package/dist/bin/resolver-DymnxKPB-UI_9xIg2.mjs +0 -16
- package/dist/bin/src-BwxUhqZU-Dr1MNcyS.mjs +0 -5046
- package/dist/bin/tsc-TmK__neM.mjs +0 -406
package/dist/bin/qvite.mjs
CHANGED
|
@@ -2,45 +2,85 @@
|
|
|
2
2
|
import { cac } from "cac";
|
|
3
3
|
import { build, createServer, loadEnv, mergeConfig } from "vite";
|
|
4
4
|
import { PersistentStore, deepMerge } from "@quiteer/utils";
|
|
5
|
-
import { Progress, UnoCSS, Vue, VueDevTools, VueJsx, bootstrapEnv, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
|
|
6
|
-
import {
|
|
5
|
+
import { AutoImport, Components, Icons, IconsResolver, NaiveUiResolver, Progress, UnoCSS, Vue, VueDevTools, VueJsx, bootstrapEnv, createSvgIconsPlugin, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
|
|
6
|
+
import path, { join, resolve } from "node:path";
|
|
7
7
|
import { cwd } from "node:process";
|
|
8
|
-
import { join } from "node:path";
|
|
9
8
|
import { isFunction } from "@quiteer/is";
|
|
10
9
|
import { parserConfig } from "@quiteer/parser-config";
|
|
11
10
|
import { pathExists } from "fs-extra";
|
|
11
|
+
import { setTimeout } from "node:timers/promises";
|
|
12
12
|
import { getPortPromise } from "portfinder";
|
|
13
13
|
|
|
14
14
|
//#region package.json
|
|
15
|
-
var version = "0.
|
|
15
|
+
var version = "0.1.1";
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/store.ts
|
|
19
|
+
const store = PersistentStore.getInstance("qvite");
|
|
20
|
+
store.set("root", cwd());
|
|
21
|
+
store.set("command", "serve");
|
|
22
|
+
store.set("config", "qvite.config.ts");
|
|
23
|
+
store.set("mode", "development");
|
|
24
|
+
store.set("env", {});
|
|
25
|
+
store.set("minify", false);
|
|
26
|
+
store.set("port", 8080);
|
|
27
|
+
store.set("prefixes", ["QVITE_", "VITE_"]);
|
|
16
28
|
|
|
17
29
|
//#endregion
|
|
18
30
|
//#region src/defaults.ts
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
function getDefaultOptions() {
|
|
32
|
+
const root$1 = store.get("root");
|
|
33
|
+
const src = resolve(root$1, "src");
|
|
34
|
+
console.log("src :>> ", src);
|
|
35
|
+
return {
|
|
36
|
+
plugins: {
|
|
37
|
+
Vue: [{ customElement: true }],
|
|
38
|
+
UnoCSS: false,
|
|
39
|
+
VueDevTools: [{}],
|
|
40
|
+
VueJsx: [{}],
|
|
41
|
+
Progress: [{}],
|
|
42
|
+
FileChangeLogger: false,
|
|
43
|
+
RemoveConsole: false,
|
|
44
|
+
MockRouter: false,
|
|
45
|
+
Icons: false,
|
|
46
|
+
SvgIcons: false,
|
|
47
|
+
AutoImport: [{ imports: [
|
|
48
|
+
"vue",
|
|
49
|
+
"vue-router",
|
|
50
|
+
{ "naive-ui": [
|
|
51
|
+
"useDialog",
|
|
52
|
+
"useMessage",
|
|
53
|
+
"useNotification",
|
|
54
|
+
"useLoadingBar"
|
|
55
|
+
] }
|
|
56
|
+
] }],
|
|
57
|
+
Components: [{
|
|
58
|
+
types: [{
|
|
59
|
+
from: "vue-router",
|
|
60
|
+
names: ["RouterLink", "RouterView"]
|
|
61
|
+
}],
|
|
62
|
+
resolvers: [NaiveUiResolver(), IconsResolver({
|
|
63
|
+
customCollections: "local",
|
|
64
|
+
componentPrefix: "icon-loacl"
|
|
65
|
+
})]
|
|
66
|
+
}]
|
|
39
67
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
68
|
+
html: {},
|
|
69
|
+
env: {
|
|
70
|
+
obfuscate: false,
|
|
71
|
+
requiredKeys: ["desc"]
|
|
72
|
+
},
|
|
73
|
+
vite: {
|
|
74
|
+
server: {
|
|
75
|
+
port: 3e3,
|
|
76
|
+
open: false,
|
|
77
|
+
strictPort: false
|
|
78
|
+
},
|
|
79
|
+
resolve: { alias: { "@": resolve(root$1, "src") } },
|
|
80
|
+
build: { minify: false }
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
44
84
|
|
|
45
85
|
//#endregion
|
|
46
86
|
//#region src/plugins.ts
|
|
@@ -52,25 +92,17 @@ var plugins_default = {
|
|
|
52
92
|
Vue,
|
|
53
93
|
VueDevTools,
|
|
54
94
|
VueJsx,
|
|
55
|
-
UnoCSS
|
|
95
|
+
UnoCSS,
|
|
96
|
+
Components,
|
|
97
|
+
SvgIcons: createSvgIconsPlugin,
|
|
98
|
+
Icons,
|
|
99
|
+
AutoImport
|
|
56
100
|
};
|
|
57
101
|
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/store.ts
|
|
60
|
-
const store = PersistentStore.getInstance("qvite");
|
|
61
|
-
store.set("root", cwd());
|
|
62
|
-
store.set("command", "serve");
|
|
63
|
-
store.set("config", "qvite.config.ts");
|
|
64
|
-
store.set("mode", "development");
|
|
65
|
-
store.set("env", {});
|
|
66
|
-
store.set("minify", false);
|
|
67
|
-
store.set("port", 8080);
|
|
68
|
-
store.set("prefixes", ["QVITE_", "VITE_"]);
|
|
69
|
-
|
|
70
102
|
//#endregion
|
|
71
103
|
//#region src/transform.ts
|
|
72
104
|
async function normalizeConfig(raw) {
|
|
73
|
-
return deepMerge(
|
|
105
|
+
return deepMerge(getDefaultOptions(), raw);
|
|
74
106
|
}
|
|
75
107
|
function geVitePlugins(config) {
|
|
76
108
|
const { html, env, plugins } = config;
|
|
@@ -124,7 +156,7 @@ async function toViteInlineConfig(config) {
|
|
|
124
156
|
async function build$1(options) {
|
|
125
157
|
const normalized = await normalizeConfig(options);
|
|
126
158
|
if (normalized.tsdown && (Array.isArray(normalized.tsdown) && normalized.tsdown.length > 0 || !Array.isArray(normalized.tsdown) && Object.keys(normalized.tsdown).length > 0)) {
|
|
127
|
-
const { build: tsdownBuild } = await import("
|
|
159
|
+
const { build: tsdownBuild } = await import("tsdown");
|
|
128
160
|
await tsdownBuild(normalized.tsdown);
|
|
129
161
|
}
|
|
130
162
|
await build(await toViteInlineConfig(normalized));
|
|
@@ -191,6 +223,7 @@ async function getConfig(filePath) {
|
|
|
191
223
|
* @remarks
|
|
192
224
|
* - 若配置的 `port` 被占用,将自动选取下一个可用端口
|
|
193
225
|
* - 启动前执行一次 tsdown 构建,便于开发期产物可用
|
|
226
|
+
* - 监控 `qvite.config.*` 变更并自动重启开发服务器(防抖)
|
|
194
227
|
*
|
|
195
228
|
* @security
|
|
196
229
|
* 不暴露敏感信息,仅打印本地 URL
|
|
@@ -213,10 +246,49 @@ async function watch(options) {
|
|
|
213
246
|
await viteDevServer.listen(p);
|
|
214
247
|
viteDevServer.printUrls();
|
|
215
248
|
if (normalized.tsdown) {
|
|
216
|
-
const { build: tsdownBuild } = await import("
|
|
249
|
+
const { build: tsdownBuild } = await import("tsdown");
|
|
217
250
|
if (!Array.isArray(normalized.tsdown)) await tsdownBuild(normalized.tsdown);
|
|
218
251
|
else await Promise.all(normalized.tsdown.map(tsdownBuild));
|
|
219
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* 自动重启:监听 qvite 配置文件变更
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* - 使用 Vite 的内部 `chokidar` watcher,避免额外依赖
|
|
258
|
+
* - 统一监听多种后缀:`.ts`、`.mjs`、`.cjs`、`.js`、`.json`
|
|
259
|
+
* - 采用简单防抖,避免短时间内多次触发
|
|
260
|
+
*/
|
|
261
|
+
const root$1 = store.get("root");
|
|
262
|
+
const configBase = store.get("config") || "qvite.config.ts";
|
|
263
|
+
const candidates = [
|
|
264
|
+
"ts",
|
|
265
|
+
"mjs",
|
|
266
|
+
"cjs",
|
|
267
|
+
"js",
|
|
268
|
+
"json"
|
|
269
|
+
].map((s) => path.join(root$1, `qvite.config.${s}`));
|
|
270
|
+
const customPath = path.isAbsolute(configBase) ? configBase : path.join(root$1, configBase);
|
|
271
|
+
const watchList = Array.from(new Set([customPath, ...candidates]));
|
|
272
|
+
viteDevServer.watcher.add(watchList);
|
|
273
|
+
let pending = false;
|
|
274
|
+
const restart = async () => {
|
|
275
|
+
if (pending) return;
|
|
276
|
+
pending = true;
|
|
277
|
+
await setTimeout(150);
|
|
278
|
+
try {
|
|
279
|
+
viteDevServer.config.logger.info(`[qvite] 检测到配置变更,正在重启开发服务器...`);
|
|
280
|
+
await viteDevServer.close();
|
|
281
|
+
await watch(await getConfig(store.get("config") || "qvite.config.ts"));
|
|
282
|
+
} catch (e) {
|
|
283
|
+
viteDevServer.config.logger.error(`[qvite] 重启失败:${e.message}`);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
viteDevServer.watcher.on("change", (changedPath) => {
|
|
287
|
+
if (watchList.includes(changedPath)) restart();
|
|
288
|
+
});
|
|
289
|
+
viteDevServer.watcher.on("unlink", (unlinkedPath) => {
|
|
290
|
+
if (watchList.includes(unlinkedPath)) restart();
|
|
291
|
+
});
|
|
220
292
|
}
|
|
221
293
|
|
|
222
294
|
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UserConfig, defineConfig as defineConfig$1 } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { UserConfig, defineConfig as defineConfig$1 } from "tsdown";
|
|
2
|
+
import { UserConfig as UserConfig$1, defineConfig as defineConfig$2 } from "vite";
|
|
3
|
+
import { AutoImport, Components, EnvConfig, EnvConfigPluginOptions, FileSystemIconLoader, Icons, IconsResolver, NaiveUiResolver, Progress, UnoCSS, VirtualHtmlOptions, Vue, VueDevTools, VueJsx, createSvgIconsPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin } from "@quiteer/vite-plugins";
|
|
4
4
|
|
|
5
5
|
//#region src/typings.d.ts
|
|
6
6
|
type PluginOptions<T extends (...args: any) => any> = boolean | Parameters<T>;
|
|
@@ -13,10 +13,14 @@ interface QvitePlugins {
|
|
|
13
13
|
RemoveConsole?: PluginOptions<typeof removeConsolePlugin>;
|
|
14
14
|
MockRouter?: PluginOptions<typeof mockRouterPlugin>;
|
|
15
15
|
FileChangeLogger?: PluginOptions<typeof fileChangeLoggerPlugin>;
|
|
16
|
+
Components?: PluginOptions<typeof Components>;
|
|
17
|
+
SvgIcons?: PluginOptions<typeof createSvgIconsPlugin>;
|
|
18
|
+
Icons?: PluginOptions<typeof Icons>;
|
|
19
|
+
AutoImport?: PluginOptions<typeof AutoImport>;
|
|
16
20
|
}
|
|
17
21
|
interface QviteConfig {
|
|
18
|
-
vite?: UserConfig;
|
|
19
|
-
tsdown?: UserConfig
|
|
22
|
+
vite?: UserConfig$1;
|
|
23
|
+
tsdown?: UserConfig | UserConfig[];
|
|
20
24
|
plugins?: QvitePlugins;
|
|
21
25
|
html?: VirtualHtmlOptions;
|
|
22
26
|
env?: EnvConfigPluginOptions;
|
|
@@ -87,7 +91,7 @@ declare function defineConfig(config: QviteConfigExport): QviteConfigExport;
|
|
|
87
91
|
* @performance
|
|
88
92
|
* 常量时间委托,无额外开销
|
|
89
93
|
*/
|
|
90
|
-
declare function defineViteConfig(config: Parameters<typeof defineConfig$
|
|
94
|
+
declare function defineViteConfig(config: Parameters<typeof defineConfig$2>[0]): ReturnType<typeof defineConfig$2>;
|
|
91
95
|
/**
|
|
92
96
|
* 暴露 tsdown 的 `defineConfig`(类型辅助包装)
|
|
93
97
|
*
|
|
@@ -113,6 +117,6 @@ declare function defineViteConfig(config: Parameters<typeof defineConfig$1>[0]):
|
|
|
113
117
|
* @performance
|
|
114
118
|
* 常量时间委托,无额外开销
|
|
115
119
|
*/
|
|
116
|
-
declare function defineTsdownConfig(config: Parameters<typeof defineConfig$
|
|
120
|
+
declare function defineTsdownConfig(config: Parameters<typeof defineConfig$1>[0]): ReturnType<typeof defineConfig$1>;
|
|
117
121
|
//#endregion
|
|
118
|
-
export { Command, ConfigEnv, type EnvConfig, Mode, PluginOptions, QviteConfig, QviteConfigExport, QviteConfigFn, QviteConfigFnObject, QviteConfigFnPromise, QvitePlugins, defineConfig, defineTsdownConfig, defineViteConfig };
|
|
122
|
+
export { Command, ConfigEnv, type EnvConfig, FileSystemIconLoader, IconsResolver, Mode, NaiveUiResolver, PluginOptions, QviteConfig, QviteConfigExport, QviteConfigFn, QviteConfigFnObject, QviteConfigFnPromise, QvitePlugins, defineConfig, defineTsdownConfig, defineViteConfig };
|