@quiteer/vite 0.0.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/README.md +160 -0
- package/cli.ts +62 -0
- package/dist/bin/context-Db5EuGKU-B3vpL0eS.mjs +24 -0
- package/dist/bin/dist-BmyFpZwL.mjs +7 -0
- package/dist/bin/dist-BniM_x9D.mjs +5256 -0
- package/dist/bin/dist-Bvgk2hb8.mjs +187 -0
- package/dist/bin/dist-CjNY_432.mjs +473 -0
- package/dist/bin/dist-DQNZhGEj.mjs +10562 -0
- package/dist/bin/esm-CQYKr9An.mjs +1557 -0
- package/dist/bin/experimental-index-DiVJ_oZg.mjs +71 -0
- package/dist/bin/qvite.mjs +244 -0
- package/dist/bin/resolver-DymnxKPB-UI_9xIg2.mjs +16 -0
- package/dist/bin/src-BwxUhqZU-Dr1MNcyS.mjs +5046 -0
- package/dist/bin/tsc-TmK__neM.mjs +406 -0
- package/dist/index.d.mts +118 -0
- package/dist/index.mjs +5965 -0
- package/index.ts +106 -0
- package/package.json +60 -0
- package/src/build.ts +43 -0
- package/src/defaults.ts +36 -0
- package/src/getConfig.ts +52 -0
- package/src/plugins.ts +14 -0
- package/src/store.ts +13 -0
- package/src/transform.ts +50 -0
- package/src/typings.ts +48 -0
- package/src/watch.ts +60 -0
- package/tsconfig.json +24 -0
- package/tsdown.config.ts +20 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { o as __toESM, s as require_binding, t as BuiltinPlugin } from "./src-BwxUhqZU-Dr1MNcyS.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
//#region rolldown:runtime
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __commonJS = (cb, mod) => function() {
|
|
13
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
|
+
key = keys[i];
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: ((k) => from[k]).bind(null, key),
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region ../../node_modules/.pnpm/rolldown-plugin-dts@0.17.4_rolldown@1.0.0-beta.47_typescript@5.9.3_vue-tsc@3.1.3_typescript@5.9.3_/node_modules/rolldown-plugin-dts/dist/filename-DhMOFFZT.mjs
|
|
32
|
+
const RE_JS = /\.([cm]?)jsx?$/;
|
|
33
|
+
const RE_TS = /\.([cm]?)tsx?$/;
|
|
34
|
+
const RE_DTS = /\.d\.([cm]?)ts$/;
|
|
35
|
+
const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
|
|
36
|
+
const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
37
|
+
const RE_CSS = /\.css$/;
|
|
38
|
+
const RE_VUE = /\.vue$/;
|
|
39
|
+
const RE_JSON = /\.json$/;
|
|
40
|
+
function filename_js_to_dts(id) {
|
|
41
|
+
return id.replace(RE_JS, ".d.$1ts");
|
|
42
|
+
}
|
|
43
|
+
function filename_to_dts(id) {
|
|
44
|
+
return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".d.ts");
|
|
45
|
+
}
|
|
46
|
+
function filename_dts_to(id, ext) {
|
|
47
|
+
return id.replace(RE_DTS, `.$1${ext}`);
|
|
48
|
+
}
|
|
49
|
+
function resolveTemplateFn(fn, chunk) {
|
|
50
|
+
return typeof fn === "function" ? fn(chunk) : fn;
|
|
51
|
+
}
|
|
52
|
+
function replaceTemplateName(template, name) {
|
|
53
|
+
return template.replaceAll("[name]", name);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region ../../node_modules/.pnpm/rolldown@1.0.0-beta.47/node_modules/rolldown/dist/experimental-index.mjs
|
|
58
|
+
var import_binding$1 = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
59
|
+
function importGlobPlugin(config) {
|
|
60
|
+
return new BuiltinPlugin("builtin:import-glob", config);
|
|
61
|
+
}
|
|
62
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
63
|
+
var BindingRebuildStrategy = import_binding.BindingRebuildStrategy;
|
|
64
|
+
var ResolverFactory = import_binding.ResolverFactory;
|
|
65
|
+
var isolatedDeclaration = import_binding.isolatedDeclaration;
|
|
66
|
+
var minify = import_binding.minify;
|
|
67
|
+
var moduleRunnerTransform = import_binding.moduleRunnerTransform;
|
|
68
|
+
var transform = import_binding.transform;
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { __commonJS as _, RE_DTS as a, RE_JSON as c, RE_VUE as d, filename_dts_to as f, resolveTemplateFn as g, replaceTemplateName as h, RE_CSS as i, RE_NODE_MODULES as l, filename_to_dts as m, importGlobPlugin as n, RE_DTS_MAP as o, filename_js_to_dts as p, isolatedDeclaration as r, RE_JS as s, ResolverFactory as t, RE_TS as u, __toESM$1 as v };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cac } from "cac";
|
|
3
|
+
import { build, createServer, loadEnv, mergeConfig } from "vite";
|
|
4
|
+
import { PersistentStore, deepMerge } from "@quiteer/utils";
|
|
5
|
+
import { Progress, UnoCSS, Vue, VueDevTools, VueJsx, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { cwd } from "node:process";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { isFunction } from "@quiteer/is";
|
|
10
|
+
import { parserConfig } from "@quiteer/parser-config";
|
|
11
|
+
import { pathExists } from "fs-extra";
|
|
12
|
+
import { getPortPromise } from "portfinder";
|
|
13
|
+
|
|
14
|
+
//#region package.json
|
|
15
|
+
var version = "0.0.1";
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/defaults.ts
|
|
19
|
+
const defaultOptions = {
|
|
20
|
+
plugins: {
|
|
21
|
+
Vue: [{ customElement: true }],
|
|
22
|
+
UnoCSS: false,
|
|
23
|
+
VueDevTools: [{}],
|
|
24
|
+
VueJsx: [{}],
|
|
25
|
+
Progress: [{}],
|
|
26
|
+
FileChangeLogger: [{}],
|
|
27
|
+
RemoveConsole: [{}],
|
|
28
|
+
MockRouter: [{}]
|
|
29
|
+
},
|
|
30
|
+
html: {},
|
|
31
|
+
env: {
|
|
32
|
+
obfuscate: false,
|
|
33
|
+
requiredKeys: ["desc"]
|
|
34
|
+
},
|
|
35
|
+
vite: {
|
|
36
|
+
server: {
|
|
37
|
+
port: 3e3,
|
|
38
|
+
strictPort: false
|
|
39
|
+
},
|
|
40
|
+
resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) } },
|
|
41
|
+
build: { minify: false }
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/plugins.ts
|
|
47
|
+
var plugins_default = {
|
|
48
|
+
FileChangeLogger: fileChangeLoggerPlugin,
|
|
49
|
+
MockRouter: mockRouterPlugin,
|
|
50
|
+
RemoveConsole: removeConsolePlugin,
|
|
51
|
+
Progress,
|
|
52
|
+
Vue,
|
|
53
|
+
VueDevTools,
|
|
54
|
+
VueJsx,
|
|
55
|
+
UnoCSS
|
|
56
|
+
};
|
|
57
|
+
|
|
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
|
+
//#endregion
|
|
71
|
+
//#region src/transform.ts
|
|
72
|
+
async function normalizeConfig(raw) {
|
|
73
|
+
return deepMerge(defaultOptions, raw);
|
|
74
|
+
}
|
|
75
|
+
function geVitePlugins(config) {
|
|
76
|
+
const { html, env, plugins } = config;
|
|
77
|
+
return [
|
|
78
|
+
...Object.keys(plugins).map((key) => {
|
|
79
|
+
const pluginOptions = plugins[key];
|
|
80
|
+
const pluginFn = plugins_default[key];
|
|
81
|
+
if (Array.isArray(pluginOptions)) return pluginFn(...pluginOptions);
|
|
82
|
+
return null;
|
|
83
|
+
}).filter(Boolean),
|
|
84
|
+
virtualHtmlPlugin(html),
|
|
85
|
+
envConfigPlugin(env)
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
async function toViteInlineConfig(config) {
|
|
89
|
+
const mode = store.get("mode");
|
|
90
|
+
return mergeConfig({
|
|
91
|
+
configFile: false,
|
|
92
|
+
root: store.get("root"),
|
|
93
|
+
mode,
|
|
94
|
+
plugins: geVitePlugins(config)
|
|
95
|
+
}, { ...config.vite });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/build.ts
|
|
100
|
+
/**
|
|
101
|
+
* 执行构建流程(生产模式)
|
|
102
|
+
*
|
|
103
|
+
* 先构建 tsdown 产物(若配置提供),再调用 Vite 的 `build` 完成前端打包
|
|
104
|
+
*
|
|
105
|
+
* @param options - Qvite 配置对象,含 `vite` 与 `tsdown` 等子配置
|
|
106
|
+
* @returns Promise<void> 构建完成无返回值
|
|
107
|
+
* @throws {Error} 当 Vite 或 tsdown 构建失败时抛出异常
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* await build({ mode: 'production', minify: true, vite: { build: { outDir: 'dist' } } })
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* - `minify` 会映射为 Vite 的 `build.minify`
|
|
116
|
+
* - 若 `tsdown` 配置存在,则会先执行 `tsdownBuild`
|
|
117
|
+
*
|
|
118
|
+
* @security
|
|
119
|
+
* 不写入敏感信息,仅调用编译器
|
|
120
|
+
*
|
|
121
|
+
* @performance
|
|
122
|
+
* 构建性能取决于 Vite/tsdown 自身实现
|
|
123
|
+
*/
|
|
124
|
+
async function build$1(options) {
|
|
125
|
+
const normalized = await normalizeConfig(options);
|
|
126
|
+
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("./dist-BniM_x9D.mjs");
|
|
128
|
+
await tsdownBuild(normalized.tsdown);
|
|
129
|
+
}
|
|
130
|
+
await build(await toViteInlineConfig(normalized));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/getConfig.ts
|
|
135
|
+
const NOT_FOUND = "找不到 qvite.config.ts | qvite.config.js | qvite.config.json , 请在根目录下添加配置文件 , 或显式的指定配置文件路径(相对于根目录)";
|
|
136
|
+
const PARSING_FAILED = "找到了配置文件,但解析配置文件失败!";
|
|
137
|
+
const root = store.get("root");
|
|
138
|
+
async function configPath(filePath) {
|
|
139
|
+
if (filePath) return join(root, filePath);
|
|
140
|
+
const configList = [
|
|
141
|
+
"ts",
|
|
142
|
+
"mjs",
|
|
143
|
+
"cjs",
|
|
144
|
+
"js"
|
|
145
|
+
].map((suffix) => `${join(root, "qvite.config")}.${suffix}`);
|
|
146
|
+
const index = (await Promise.all(configList.map((path$1) => pathExists(path$1)))).findIndex((flag) => flag);
|
|
147
|
+
if (index > -1) return configList[index];
|
|
148
|
+
throw new Error(NOT_FOUND);
|
|
149
|
+
}
|
|
150
|
+
async function getConfig(filePath) {
|
|
151
|
+
const path$1 = await configPath(filePath);
|
|
152
|
+
const command = store.get("command");
|
|
153
|
+
const mode = store.get("mode");
|
|
154
|
+
const modeEnv = loadEnv(mode, root, store.get("prefixes"));
|
|
155
|
+
const env = deepMerge({}, loadEnv("", root, store.get("prefixes")), modeEnv);
|
|
156
|
+
try {
|
|
157
|
+
const option = await parserConfig(path$1, "qvite.config");
|
|
158
|
+
if (isFunction(option)) return option({
|
|
159
|
+
command,
|
|
160
|
+
mode,
|
|
161
|
+
env,
|
|
162
|
+
root
|
|
163
|
+
});
|
|
164
|
+
return option;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error("error :>> ", error);
|
|
167
|
+
throw new Error(PARSING_FAILED);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/watch.ts
|
|
173
|
+
/**
|
|
174
|
+
* 启动开发服务器(热更新)
|
|
175
|
+
*
|
|
176
|
+
* 根据规范化配置启动 Vite Dev Server,自动选择可用端口,并打印访问地址
|
|
177
|
+
*
|
|
178
|
+
* @param options - Qvite 配置对象,包含 `vite` 与 `tsdown`
|
|
179
|
+
* @returns Promise<void>
|
|
180
|
+
* @throws {Error} 当端口查找或 Vite 启动失败时抛出异常
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* await watch({ port: 3000, vite: { plugins: [] } })
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* - 若配置的 `port` 被占用,将自动选取下一个可用端口
|
|
189
|
+
* - 启动前执行一次 tsdown 构建,便于开发期产物可用
|
|
190
|
+
*
|
|
191
|
+
* @security
|
|
192
|
+
* 不暴露敏感信息,仅打印本地 URL
|
|
193
|
+
*
|
|
194
|
+
* @performance
|
|
195
|
+
* 端口探测为 O(1) 近似成本,服务性能由 Vite 决定
|
|
196
|
+
*/
|
|
197
|
+
async function watch(options) {
|
|
198
|
+
const normalized = await normalizeConfig(options);
|
|
199
|
+
const p = await getPortPromise({ port: normalized.vite?.server?.port || store.get("port") });
|
|
200
|
+
store.set("port", p);
|
|
201
|
+
const inline = await toViteInlineConfig(normalized);
|
|
202
|
+
const viteDevServer = await createServer({
|
|
203
|
+
...inline,
|
|
204
|
+
server: {
|
|
205
|
+
...inline.server,
|
|
206
|
+
port: p
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
await viteDevServer.listen(p);
|
|
210
|
+
viteDevServer.printUrls();
|
|
211
|
+
if (normalized.tsdown) {
|
|
212
|
+
const { build: tsdownBuild } = await import("./dist-BniM_x9D.mjs");
|
|
213
|
+
if (!Array.isArray(normalized.tsdown)) await tsdownBuild(normalized.tsdown);
|
|
214
|
+
else await Promise.all(normalized.tsdown.map(tsdownBuild));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region cli.ts
|
|
220
|
+
const cli = cac("qvite");
|
|
221
|
+
cli.option("--minify", "使代码进行压缩 ", { default: false });
|
|
222
|
+
cli.command("[config-file]", "qvite dev ,启动开发环境热更新").alias("dev").option("-m , --mode <mode>", "[development | production | test | staging | ...] 环境模式 ", { default: "development" }).option("-p , --port <port>", "[number] 渲染进程的端口号 ,如果占用会切换非占用的端口 ", { default: 8090 }).action(async (configFile = "qvite.config.ts", options) => {
|
|
223
|
+
const { mode, port, minify } = options;
|
|
224
|
+
store.set("command", "serve");
|
|
225
|
+
store.set("config", configFile);
|
|
226
|
+
store.set("mode", mode);
|
|
227
|
+
store.set("port", port);
|
|
228
|
+
store.set("minify", !!minify);
|
|
229
|
+
watch(await getConfig(configFile));
|
|
230
|
+
});
|
|
231
|
+
cli.command("build [root]", "开始构建服务 , 若不指定平台则默认当前操作系统的架构类型").option("-m , --mode <mode>", "[development | production | test | staging | ...] 环境模式 ", { default: "production" }).action(async (configFile = "qvite.config.ts", options) => {
|
|
232
|
+
const { mode, minify } = options;
|
|
233
|
+
store.set("command", "build");
|
|
234
|
+
store.set("config", configFile);
|
|
235
|
+
store.set("mode", mode);
|
|
236
|
+
store.set("minify", minify);
|
|
237
|
+
build$1(await getConfig(configFile));
|
|
238
|
+
});
|
|
239
|
+
cli.help();
|
|
240
|
+
cli.version(version);
|
|
241
|
+
cli.parse();
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/rolldown-plugin-dts@0.17.4_rolldown@1.0.0-beta.47_typescript@5.9.3_vue-tsc@3.1.3_typescript@5.9.3_/node_modules/rolldown-plugin-dts/dist/resolver-DymnxKPB.mjs
|
|
2
|
+
const __cjs_require = globalThis.process.getBuiltinModule("module").createRequire(import.meta.url);
|
|
3
|
+
const Debug = __cjs_require("debug");
|
|
4
|
+
const path = globalThis.process.getBuiltinModule("node:path");
|
|
5
|
+
const ts = __cjs_require("typescript");
|
|
6
|
+
const debug = Debug("rolldown-plugin-dts:tsc-resolver");
|
|
7
|
+
function tscResolve(id, importer, cwd, tsconfig, tsconfigRaw, reference) {
|
|
8
|
+
const baseDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
9
|
+
const parsedConfig = ts.parseJsonConfigFileContent(tsconfigRaw, ts.sys, baseDir);
|
|
10
|
+
const resolved = ts.bundlerModuleNameResolver(id, importer, parsedConfig.options, ts.sys, void 0, reference);
|
|
11
|
+
debug(`tsc resolving id "%s" from "%s" -> %O`, id, importer, resolved.resolvedModule);
|
|
12
|
+
return resolved.resolvedModule?.resolvedFileName;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { tscResolve };
|