@moluoxixi/vite-config 0.0.37

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.
Files changed (50) hide show
  1. package/DESIGN.md +70 -0
  2. package/README.md +71 -0
  3. package/dist/addons/auto-import.d.ts +9 -0
  4. package/dist/addons/auto-import.js +6 -0
  5. package/dist/addons/components.d.ts +9 -0
  6. package/dist/addons/components.js +6 -0
  7. package/dist/addons/devtools.d.ts +9 -0
  8. package/dist/addons/devtools.js +6 -0
  9. package/dist/addons/i18n.d.ts +9 -0
  10. package/dist/addons/i18n.js +6 -0
  11. package/dist/addons/index.d.ts +28 -0
  12. package/dist/addons/index.js +59 -0
  13. package/dist/addons/layouts.d.ts +9 -0
  14. package/dist/addons/layouts.js +6 -0
  15. package/dist/addons/markdown.d.ts +9 -0
  16. package/dist/addons/markdown.js +6 -0
  17. package/dist/addons/pwa.d.ts +9 -0
  18. package/dist/addons/pwa.js +6 -0
  19. package/dist/addons/react.d.ts +9 -0
  20. package/dist/addons/react.js +6 -0
  21. package/dist/addons/tailwindcss.d.ts +9 -0
  22. package/dist/addons/tailwindcss.js +6 -0
  23. package/dist/addons/unocss.d.ts +9 -0
  24. package/dist/addons/unocss.js +6 -0
  25. package/dist/addons/vite-ssg.d.ts +18 -0
  26. package/dist/addons/vite-ssg.js +6 -0
  27. package/dist/addons/vitest.d.ts +9 -0
  28. package/dist/addons/vitest.js +6 -0
  29. package/dist/addons/vue-router.d.ts +9 -0
  30. package/dist/addons/vue-router.js +6 -0
  31. package/dist/addons/vue.d.ts +9 -0
  32. package/dist/addons/vue.js +6 -0
  33. package/dist/chunk-2BMF52EY.js +8 -0
  34. package/dist/chunk-7CLRGPQQ.js +8 -0
  35. package/dist/chunk-CG74BJ6T.js +8 -0
  36. package/dist/chunk-GKIEBF73.js +8 -0
  37. package/dist/chunk-GUIZM2YS.js +8 -0
  38. package/dist/chunk-HKGBYIAA.js +8 -0
  39. package/dist/chunk-IBJFH5NC.js +8 -0
  40. package/dist/chunk-M2ZFVZSN.js +8 -0
  41. package/dist/chunk-NQPL76JU.js +8 -0
  42. package/dist/chunk-OEBLHHRC.js +8 -0
  43. package/dist/chunk-PBJLIQ2R.js +8 -0
  44. package/dist/chunk-T5FUYGUC.js +0 -0
  45. package/dist/chunk-UXLJ2PKX.js +8 -0
  46. package/dist/chunk-WYQMKXD6.js +8 -0
  47. package/dist/chunk-YMSTBWUP.js +8 -0
  48. package/dist/index.d.ts +138 -0
  49. package/dist/index.js +815 -0
  50. package/package.json +183 -0
package/dist/index.js ADDED
@@ -0,0 +1,815 @@
1
+ import "./chunk-T5FUYGUC.js";
2
+ import {
3
+ definePwaAddonOptions
4
+ } from "./chunk-2BMF52EY.js";
5
+ import {
6
+ defineReactAddonOptions
7
+ } from "./chunk-PBJLIQ2R.js";
8
+ import {
9
+ defineTailwindCssAddonOptions
10
+ } from "./chunk-HKGBYIAA.js";
11
+ import {
12
+ defineUnoCssAddonOptions
13
+ } from "./chunk-7CLRGPQQ.js";
14
+ import {
15
+ defineViteSsgAddonOptions
16
+ } from "./chunk-YMSTBWUP.js";
17
+ import {
18
+ defineVitestAddonOptions
19
+ } from "./chunk-UXLJ2PKX.js";
20
+ import {
21
+ defineVueRouterAddonOptions
22
+ } from "./chunk-WYQMKXD6.js";
23
+ import {
24
+ defineVueAddonOptions
25
+ } from "./chunk-M2ZFVZSN.js";
26
+ import {
27
+ defineAutoImportAddonOptions
28
+ } from "./chunk-GUIZM2YS.js";
29
+ import {
30
+ defineComponentsAddonOptions
31
+ } from "./chunk-NQPL76JU.js";
32
+ import {
33
+ defineDevtoolsAddonOptions
34
+ } from "./chunk-OEBLHHRC.js";
35
+ import {
36
+ defineI18nAddonOptions
37
+ } from "./chunk-IBJFH5NC.js";
38
+ import {
39
+ defineVueLayoutsAddonOptions
40
+ } from "./chunk-GKIEBF73.js";
41
+ import {
42
+ defineMarkdownAddonOptions
43
+ } from "./chunk-CG74BJ6T.js";
44
+
45
+ // src/config/app.ts
46
+ import { defineConfig, mergeConfig as mergeConfig3 } from "vite";
47
+
48
+ // src/config/base/index.ts
49
+ import path2 from "path";
50
+ import process2 from "process";
51
+ import { mergeConfig as mergeConfig2 } from "vite";
52
+
53
+ // src/config/base/addons/index.ts
54
+ import { mergeConfig } from "vite";
55
+
56
+ // src/config/base/addons/runtime.ts
57
+ import path from "path";
58
+ import process from "process";
59
+ import { detectDependencies } from "@moluoxixi/core";
60
+ function defineFeature(feature) {
61
+ return feature;
62
+ }
63
+ function getPackageName(specifier) {
64
+ const parts = specifier.split("/");
65
+ if (specifier.startsWith("@")) {
66
+ return `${parts[0]}/${parts[1]}`;
67
+ }
68
+ return parts[0];
69
+ }
70
+ function isAddonPayload(option) {
71
+ return typeof option === "object" && option !== null && !Array.isArray(option) || typeof option === "string";
72
+ }
73
+ function inspectFeature(ctx, feature, option) {
74
+ const requires = feature.requires || [];
75
+ const matchedTriggers = feature.triggers.filter(ctx.hasAddonDep);
76
+ const missingRequires = requires.filter((dep) => !ctx.hasAddonDep(dep));
77
+ if (option === false) {
78
+ return {
79
+ enabled: false,
80
+ matchedTriggers,
81
+ missingRequires: [],
82
+ name: feature.name,
83
+ reason: "explicit-disabled",
84
+ requires,
85
+ triggers: feature.triggers
86
+ };
87
+ }
88
+ if (option === true || isAddonPayload(option)) {
89
+ return {
90
+ enabled: true,
91
+ matchedTriggers,
92
+ missingRequires,
93
+ name: feature.name,
94
+ reason: "explicit-enabled",
95
+ requires,
96
+ triggers: feature.triggers
97
+ };
98
+ }
99
+ if (matchedTriggers.length > 0) {
100
+ return {
101
+ enabled: true,
102
+ matchedTriggers,
103
+ missingRequires,
104
+ name: feature.name,
105
+ reason: "dependency-detected",
106
+ requires,
107
+ triggers: feature.triggers
108
+ };
109
+ }
110
+ return {
111
+ enabled: false,
112
+ matchedTriggers,
113
+ missingRequires: [],
114
+ name: feature.name,
115
+ reason: "dependency-missing",
116
+ requires,
117
+ triggers: feature.triggers
118
+ };
119
+ }
120
+ function createAddonContext(options = {}) {
121
+ const rootValue = options.viteConfig?.root;
122
+ const root = path.resolve(typeof rootValue === "string" ? rootValue : process.cwd());
123
+ const { addonDeps, deps, runtimeDeps } = detectDependencies(root);
124
+ const importCache = /* @__PURE__ */ new Map();
125
+ const hasAddonDep = (name) => Boolean(addonDeps[name]);
126
+ const hasDep = (name) => Boolean(deps[name]);
127
+ const hasRuntimeDep = (name) => Boolean(runtimeDeps[name]);
128
+ const requireDeps = (owner, requiredDeps) => {
129
+ const missing = requiredDeps.filter((dep) => !hasAddonDep(dep));
130
+ if (missing.length > 0) {
131
+ throw new Error(`[ViteConfig] ${owner} requires missing package(s): ${missing.join(", ")}. Checked ${path.resolve(root, "package.json")}`);
132
+ }
133
+ };
134
+ const importRequired = async (owner, specifier) => {
135
+ const packageName = getPackageName(specifier);
136
+ requireDeps(owner, [packageName]);
137
+ if (!importCache.has(specifier)) {
138
+ importCache.set(
139
+ specifier,
140
+ import(specifier).catch((cause) => {
141
+ throw new Error(`[ViteConfig] ${owner} failed to load ${specifier}. Install ${packageName} for project root ${root}.`, { cause });
142
+ })
143
+ );
144
+ }
145
+ return await importCache.get(specifier);
146
+ };
147
+ return {
148
+ addonDeps,
149
+ deps,
150
+ hasAddonDep,
151
+ hasAnyAddonDep: (names) => names.some(hasAddonDep),
152
+ hasAnyDep: (names) => names.some(hasDep),
153
+ hasAnyRuntimeDep: (names) => names.some(hasRuntimeDep),
154
+ hasDep,
155
+ hasRuntimeDep,
156
+ importRequired,
157
+ requireDeps,
158
+ resolvePath: (...segments) => path.resolve(root, ...segments),
159
+ root,
160
+ runtimeDeps
161
+ };
162
+ }
163
+ async function resolveFeatureConfig(ctx, feature, option) {
164
+ const options = isAddonPayload(option) ? option : void 0;
165
+ try {
166
+ ctx.requireDeps(feature.name, feature.requires || []);
167
+ const state = feature.createState ? feature.createState(ctx, options) : void 0;
168
+ return await feature.setup(ctx, options, state);
169
+ } catch (cause) {
170
+ if (cause instanceof Error && cause.message.startsWith("[ViteConfig]")) {
171
+ throw cause;
172
+ }
173
+ throw new Error(`[ViteConfig] failed to resolve addon ${feature.name}`, { cause });
174
+ }
175
+ }
176
+
177
+ // src/config/base/addons/shared.ts
178
+ import { defu } from "defu";
179
+ var HTTP_URL_PATTERN = /^https?:\/\//;
180
+ var MARKDOWN_PATTERN = /\.md$/;
181
+ var VUE_I18N_PATTERN = /vue-i18n/;
182
+ var VUE_PATTERN = /\.vue$/;
183
+ var JS_TS_PATTERN = /\.[jt]sx?$/;
184
+ var MARKDOWN_PLUGIN_NAMES = ["unplugin-vue-markdown", "vite-plugin-md", "vite-plugin-vue-markdown"];
185
+ var SVELTE_PATTERN = /\.svelte$/;
186
+ var VUE_QUERY_PATTERN = /\.vue\?vue/;
187
+ function mergeAddonOptions(options, defaultOptions) {
188
+ return defu(options, defaultOptions);
189
+ }
190
+ async function callDefaultFactory(ctx, owner, specifier, options) {
191
+ const mod = await ctx.importRequired(owner, specifier);
192
+ if (typeof mod.default !== "function") {
193
+ throw new TypeError(`[ViteConfig] ${owner} expected ${specifier} to expose a default plugin factory`);
194
+ }
195
+ return mod.default(options);
196
+ }
197
+ function hasMarkdownAddon(ctx) {
198
+ return ctx.hasAnyAddonDep(MARKDOWN_PLUGIN_NAMES);
199
+ }
200
+ function createVueIncludePatterns(ctx) {
201
+ const include = [];
202
+ if (ctx.hasAddonDep("vue")) {
203
+ include.push(VUE_PATTERN);
204
+ }
205
+ if (hasMarkdownAddon(ctx)) {
206
+ include.push(MARKDOWN_PATTERN);
207
+ }
208
+ return include;
209
+ }
210
+ function createSourceIncludePatterns(ctx) {
211
+ const include = [JS_TS_PATTERN];
212
+ if (ctx.hasAddonDep("vue")) {
213
+ include.push(VUE_PATTERN, VUE_QUERY_PATTERN);
214
+ }
215
+ if (ctx.hasAddonDep("svelte")) {
216
+ include.push(SVELTE_PATTERN);
217
+ }
218
+ if (hasMarkdownAddon(ctx)) {
219
+ include.push(MARKDOWN_PATTERN);
220
+ }
221
+ return include;
222
+ }
223
+
224
+ // src/config/base/addons/auto-import.ts
225
+ function applyPresetImports(ctx, state) {
226
+ const presets = [
227
+ "vue",
228
+ "react",
229
+ "vue-i18n",
230
+ "@vueuse/core",
231
+ "@vueuse/math",
232
+ "@vueuse/head",
233
+ "vitest",
234
+ "pinia",
235
+ "preact",
236
+ "quasar",
237
+ "react-router",
238
+ "react-router-dom",
239
+ "rxjs",
240
+ "solid-js",
241
+ "svelte"
242
+ ];
243
+ for (const preset of presets) {
244
+ if (ctx.hasAddonDep(preset)) {
245
+ state.imports.push(preset);
246
+ }
247
+ }
248
+ if (!ctx.hasAddonDep("unplugin-vue-router") && ctx.hasAddonDep("vue-router")) {
249
+ state.imports.push("vue-router");
250
+ }
251
+ }
252
+ async function applyVueRouterAutoImports(ctx, state) {
253
+ if (!ctx.hasAddonDep("unplugin-vue-router")) {
254
+ return;
255
+ }
256
+ const { VueRouterAutoImports } = await ctx.importRequired("autoImport:vueRouterAutoImports", "unplugin-vue-router");
257
+ state.imports.push(VueRouterAutoImports);
258
+ state.imports.push({ "vue-router/auto": ["useLink"] });
259
+ }
260
+ async function applyUnheadAutoImports(ctx, state) {
261
+ if (!ctx.hasAddonDep("@unhead/vue")) {
262
+ return;
263
+ }
264
+ const { unheadVueComposablesImports } = await ctx.importRequired("autoImport:unheadAutoImports", "@unhead/vue");
265
+ state.imports.push(unheadVueComposablesImports);
266
+ }
267
+ async function applyElementPlusResolver(ctx, state) {
268
+ if (!ctx.hasAddonDep("element-plus")) {
269
+ return;
270
+ }
271
+ ctx.requireDeps("autoImport:elementPlusResolver", ["unplugin-vue-components"]);
272
+ const { ElementPlusResolver } = await ctx.importRequired("autoImport:elementPlusResolver", "unplugin-vue-components/resolvers");
273
+ state.resolvers.push(ElementPlusResolver());
274
+ }
275
+ var autoImportFeature = defineFeature({
276
+ name: "autoImport",
277
+ order: 50,
278
+ requires: ["unplugin-auto-import"],
279
+ triggers: ["unplugin-auto-import"],
280
+ createState(ctx) {
281
+ const state = {
282
+ imports: [],
283
+ include: createSourceIncludePatterns(ctx),
284
+ resolvers: []
285
+ };
286
+ applyPresetImports(ctx, state);
287
+ return state;
288
+ },
289
+ async setup(ctx, options, state) {
290
+ await applyVueRouterAutoImports(ctx, state);
291
+ await applyUnheadAutoImports(ctx, state);
292
+ await applyElementPlusResolver(ctx, state);
293
+ const { default: AutoImport } = await ctx.importRequired("autoImport", "unplugin-auto-import/vite");
294
+ const defaultOptions = {
295
+ dirs: ["src/composables", "src/stores", "src/utils"],
296
+ dts: ctx.resolvePath("src/typings/auto-imports.d.ts"),
297
+ imports: state.imports,
298
+ include: state.include,
299
+ ...state.resolvers.length > 0 ? { resolvers: state.resolvers } : {},
300
+ vueTemplate: ctx.hasAddonDep("vue")
301
+ };
302
+ const autoImportOptions = mergeAddonOptions(options, defaultOptions);
303
+ return {
304
+ plugins: [
305
+ AutoImport(autoImportOptions)
306
+ ]
307
+ };
308
+ }
309
+ });
310
+
311
+ // src/config/base/addons/components.ts
312
+ async function applyElementPlusResolver2(ctx, state) {
313
+ if (!ctx.hasAddonDep("element-plus")) {
314
+ return;
315
+ }
316
+ ctx.requireDeps("components:elementPlusResolver", ["unplugin-vue-components"]);
317
+ const { ElementPlusResolver } = await ctx.importRequired("components:elementPlusResolver", "unplugin-vue-components/resolvers");
318
+ state.resolvers.push(ElementPlusResolver());
319
+ }
320
+ var componentsFeature = defineFeature({
321
+ name: "components",
322
+ order: 55,
323
+ requires: ["unplugin-vue-components"],
324
+ triggers: ["unplugin-vue-components"],
325
+ createState(ctx) {
326
+ const extensions = [];
327
+ if (ctx.hasAddonDep("vue")) {
328
+ extensions.push("vue");
329
+ }
330
+ if (ctx.hasAddonDep("svelte")) {
331
+ extensions.push("svelte");
332
+ }
333
+ if (hasMarkdownAddon(ctx)) {
334
+ extensions.push("md");
335
+ }
336
+ return {
337
+ extensions,
338
+ include: createSourceIncludePatterns(ctx),
339
+ resolvers: []
340
+ };
341
+ },
342
+ async setup(ctx, options, state) {
343
+ await applyElementPlusResolver2(ctx, state);
344
+ const { default: Components } = await ctx.importRequired("components", "unplugin-vue-components/vite");
345
+ const defaultOptions = {
346
+ dts: ctx.resolvePath("src/typings/components.d.ts"),
347
+ extensions: state.extensions,
348
+ include: state.include,
349
+ ...state.resolvers.length > 0 ? { resolvers: state.resolvers } : {}
350
+ };
351
+ const componentOptions = mergeAddonOptions(options, defaultOptions);
352
+ return {
353
+ plugins: [
354
+ Components(componentOptions)
355
+ ]
356
+ };
357
+ }
358
+ });
359
+
360
+ // src/config/base/addons/devtools.ts
361
+ var devtoolsFeature = defineFeature({
362
+ name: "devtools",
363
+ order: 70,
364
+ requires: ["vite-plugin-vue-devtools"],
365
+ triggers: ["vite-plugin-vue-devtools"],
366
+ async setup(ctx, options) {
367
+ return {
368
+ plugins: [
369
+ await callDefaultFactory(ctx, "devtools", "vite-plugin-vue-devtools", options)
370
+ ]
371
+ };
372
+ }
373
+ });
374
+
375
+ // src/config/base/addons/i18n.ts
376
+ var i18nFeature = defineFeature({
377
+ name: "i18n",
378
+ order: 60,
379
+ requires: ["@intlify/unplugin-vue-i18n"],
380
+ triggers: ["@intlify/unplugin-vue-i18n"],
381
+ async setup(ctx, options) {
382
+ const { default: VueI18n } = await ctx.importRequired("i18n", "@intlify/unplugin-vue-i18n/vite");
383
+ const defaultOptions = {
384
+ compositionOnly: true,
385
+ fullInstall: true,
386
+ include: [ctx.resolvePath("locales/**")],
387
+ runtimeOnly: true
388
+ };
389
+ return {
390
+ plugins: [
391
+ VueI18n(mergeAddonOptions(options, defaultOptions))
392
+ ]
393
+ };
394
+ }
395
+ });
396
+
397
+ // src/config/base/addons/markdown.ts
398
+ var markdownFeature = defineFeature({
399
+ name: "markdown",
400
+ order: 90,
401
+ requires: ["unplugin-vue-markdown", "@shikijs/markdown-it", "markdown-it-link-attributes"],
402
+ triggers: ["unplugin-vue-markdown", "vite-plugin-vue-markdown", "vite-plugin-md"],
403
+ async setup(ctx, options) {
404
+ const { default: Markdown } = await ctx.importRequired("markdown", "unplugin-vue-markdown/vite");
405
+ const { default: Shiki } = await ctx.importRequired("markdown:shiki", "@shikijs/markdown-it");
406
+ const { default: LinkAttributes } = await ctx.importRequired("markdown:linkAttributes", "markdown-it-link-attributes");
407
+ const defaultOptions = {
408
+ async markdownItSetup(md) {
409
+ md.use(LinkAttributes, {
410
+ attrs: {
411
+ rel: "noopener",
412
+ target: "_blank"
413
+ },
414
+ matcher: (link) => HTTP_URL_PATTERN.test(link)
415
+ });
416
+ md.use(await Shiki({
417
+ defaultColor: false,
418
+ themes: {
419
+ dark: "vitesse-dark",
420
+ light: "vitesse-light"
421
+ }
422
+ }));
423
+ },
424
+ headEnabled: true,
425
+ wrapperClasses: "prose prose-sm m-auto text-left"
426
+ };
427
+ return {
428
+ plugins: [
429
+ Markdown(mergeAddonOptions(options, defaultOptions))
430
+ ]
431
+ };
432
+ }
433
+ });
434
+
435
+ // src/config/base/addons/pwa.ts
436
+ import { defu as defu2 } from "defu";
437
+ var defaultPwaOptions = {
438
+ registerType: "autoUpdate"
439
+ };
440
+ var pwaFeature = defineFeature({
441
+ name: "pwa",
442
+ order: 80,
443
+ requires: ["vite-plugin-pwa"],
444
+ triggers: ["vite-plugin-pwa"],
445
+ async setup(ctx, options) {
446
+ const { VitePWA } = await ctx.importRequired("pwa", "vite-plugin-pwa");
447
+ return {
448
+ plugins: [
449
+ VitePWA(defu2(options, defaultPwaOptions))
450
+ ]
451
+ };
452
+ }
453
+ });
454
+
455
+ // src/config/base/addons/react.ts
456
+ var reactFeature = defineFeature({
457
+ name: "react",
458
+ order: 20,
459
+ requires: ["@vitejs/plugin-react"],
460
+ triggers: ["react", "@vitejs/plugin-react"],
461
+ async setup(ctx, options) {
462
+ return {
463
+ plugins: [
464
+ await callDefaultFactory(ctx, "react", "@vitejs/plugin-react", options)
465
+ ]
466
+ };
467
+ }
468
+ });
469
+
470
+ // src/config/base/addons/tailwindcss.ts
471
+ var tailwindcssFeature = defineFeature({
472
+ name: "tailwindcss",
473
+ order: 35,
474
+ triggers: ["@tailwindcss/vite", "@tailwindcss/postcss"],
475
+ async setup(ctx, options) {
476
+ if (ctx.hasAddonDep("@tailwindcss/vite")) {
477
+ const plugins = await callDefaultFactory(ctx, "tailwindcss", "@tailwindcss/vite", options);
478
+ return {
479
+ plugins
480
+ };
481
+ }
482
+ if (ctx.hasAddonDep("@tailwindcss/postcss")) {
483
+ const { default: tailwindPostcss } = await ctx.importRequired("tailwindcss:postcss", "@tailwindcss/postcss");
484
+ return {
485
+ css: {
486
+ postcss: {
487
+ plugins: [tailwindPostcss(options)]
488
+ }
489
+ }
490
+ };
491
+ }
492
+ throw new Error("[ViteConfig] tailwindcss requires @tailwindcss/vite or @tailwindcss/postcss. Install one Tailwind CSS integration package for the target project.");
493
+ }
494
+ });
495
+
496
+ // src/config/base/addons/unocss.ts
497
+ import fs from "fs";
498
+ var UNO_CONFIG_FILES = [
499
+ "uno.config.ts",
500
+ "uno.config.mts",
501
+ "uno.config.cts",
502
+ "uno.config.js",
503
+ "uno.config.mjs",
504
+ "uno.config.cjs",
505
+ "unocss.config.ts",
506
+ "unocss.config.mts",
507
+ "unocss.config.cts",
508
+ "unocss.config.js",
509
+ "unocss.config.mjs",
510
+ "unocss.config.cjs"
511
+ ];
512
+ function resolveUnoConfigFile(ctx) {
513
+ const configFile = UNO_CONFIG_FILES.map((file) => ctx.resolvePath(file)).find((file) => fs.existsSync(file));
514
+ return configFile || false;
515
+ }
516
+ var unocssFeature = defineFeature({
517
+ name: "unocss",
518
+ order: 30,
519
+ requires: ["unocss"],
520
+ triggers: ["unocss"],
521
+ async setup(ctx, options) {
522
+ const defaultOptions = {
523
+ configFile: resolveUnoConfigFile(ctx)
524
+ };
525
+ return {
526
+ plugins: [
527
+ await callDefaultFactory(
528
+ ctx,
529
+ "unocss",
530
+ "unocss/vite",
531
+ typeof options === "string" ? options : mergeAddonOptions(options, defaultOptions)
532
+ )
533
+ ]
534
+ };
535
+ }
536
+ });
537
+
538
+ // src/config/base/addons/vite-ssg.ts
539
+ import { defu as defu3 } from "defu";
540
+ var viteSsgFeature = defineFeature({
541
+ name: "viteSsg",
542
+ order: 110,
543
+ requires: ["vite-ssg"],
544
+ triggers: ["vite-ssg"],
545
+ async setup(ctx, options) {
546
+ const noExternal = [];
547
+ if (ctx.hasAddonDep("vue-i18n")) {
548
+ noExternal.push(VUE_I18N_PATTERN);
549
+ }
550
+ const defaultOptions = {
551
+ ssgOptions: {
552
+ beastiesOptions: {
553
+ reduceInlineStyles: false
554
+ },
555
+ formatting: "minify",
556
+ script: "async"
557
+ }
558
+ };
559
+ const resolvedOptions = mergeAddonOptions(options, defaultOptions);
560
+ if (!ctx.hasAddonDep("vite-ssg-sitemap")) {
561
+ return noExternal.length > 0 ? defu3({ ssr: { noExternal } }, resolvedOptions) : resolvedOptions;
562
+ }
563
+ const { default: generateSitemap } = await ctx.importRequired("viteSsg:sitemap", "vite-ssg-sitemap");
564
+ const ssgOptions = resolvedOptions.ssgOptions;
565
+ const userOnFinished = ssgOptions?.onFinished;
566
+ return defu3({
567
+ ssgOptions: {
568
+ ...ssgOptions,
569
+ async onFinished() {
570
+ await userOnFinished?.();
571
+ await generateSitemap();
572
+ }
573
+ },
574
+ ...noExternal.length > 0 ? { ssr: { noExternal } } : {}
575
+ }, resolvedOptions);
576
+ }
577
+ });
578
+
579
+ // src/config/base/addons/vitest.ts
580
+ import { defu as defu4 } from "defu";
581
+ var vitestFeature = defineFeature({
582
+ name: "vitest",
583
+ order: 100,
584
+ triggers: ["vitest"],
585
+ setup(_ctx, options) {
586
+ const defaultOptions = {
587
+ environment: "jsdom",
588
+ include: ["test/**/*.test.ts"]
589
+ };
590
+ return {
591
+ test: defu4(options, defaultOptions)
592
+ };
593
+ }
594
+ });
595
+
596
+ // src/config/base/addons/vue.ts
597
+ var vueFeature = defineFeature({
598
+ name: "vue",
599
+ order: 10,
600
+ requires: ["@vitejs/plugin-vue"],
601
+ triggers: ["vue", "@vitejs/plugin-vue"],
602
+ async setup(ctx, options) {
603
+ const { default: vue } = await ctx.importRequired("vue", "@vitejs/plugin-vue");
604
+ const defaultOptions = {
605
+ include: createVueIncludePatterns(ctx)
606
+ };
607
+ const vuePlugin = vue(mergeAddonOptions(options, defaultOptions));
608
+ if (ctx.hasAddonDep("unplugin-vue-macros")) {
609
+ const { default: VueMacros } = await ctx.importRequired("vue:macros", "unplugin-vue-macros/vite");
610
+ return {
611
+ plugins: [
612
+ VueMacros({
613
+ plugins: {
614
+ vue: vuePlugin
615
+ }
616
+ })
617
+ ]
618
+ };
619
+ }
620
+ return { plugins: [vuePlugin] };
621
+ }
622
+ });
623
+
624
+ // src/config/base/addons/vue-layouts.ts
625
+ var vueLayoutsFeature = defineFeature({
626
+ name: "vueLayouts",
627
+ order: 45,
628
+ requires: ["vite-plugin-vue-layouts"],
629
+ triggers: ["vite-plugin-vue-layouts"],
630
+ async setup(ctx, options) {
631
+ return {
632
+ plugins: [
633
+ await callDefaultFactory(ctx, "vueLayouts", "vite-plugin-vue-layouts", options)
634
+ ]
635
+ };
636
+ }
637
+ });
638
+
639
+ // src/config/base/addons/vue-router.ts
640
+ var vueRouterFeature = defineFeature({
641
+ name: "vueRouter",
642
+ order: 40,
643
+ requires: ["unplugin-vue-router"],
644
+ triggers: ["unplugin-vue-router"],
645
+ async setup(ctx, options) {
646
+ const extensions = [];
647
+ if (ctx.hasAddonDep("vue")) {
648
+ extensions.push(".vue");
649
+ }
650
+ if (hasMarkdownAddon(ctx)) {
651
+ extensions.push(".md");
652
+ }
653
+ const defaultOptions = {
654
+ dts: ctx.resolvePath("src/typings/route-map.d.ts"),
655
+ extensions,
656
+ root: ctx.root,
657
+ routesFolder: ctx.resolvePath("src/pages")
658
+ };
659
+ return {
660
+ plugins: [
661
+ await callDefaultFactory(
662
+ ctx,
663
+ "vueRouter",
664
+ "unplugin-vue-router/vite",
665
+ mergeAddonOptions(options, defaultOptions)
666
+ )
667
+ ]
668
+ };
669
+ }
670
+ });
671
+
672
+ // src/config/base/addons/registry.ts
673
+ var features = [
674
+ vueFeature,
675
+ reactFeature,
676
+ unocssFeature,
677
+ tailwindcssFeature,
678
+ vueRouterFeature,
679
+ vueLayoutsFeature,
680
+ autoImportFeature,
681
+ componentsFeature,
682
+ i18nFeature,
683
+ devtoolsFeature,
684
+ pwaFeature,
685
+ markdownFeature,
686
+ vitestFeature,
687
+ viteSsgFeature
688
+ ];
689
+ var viteFeatures = features.sort((a, b) => a.order - b.order);
690
+
691
+ // src/config/base/addons/index.ts
692
+ function inspectViteFeatures(options = {}) {
693
+ const ctx = createAddonContext(options);
694
+ return {
695
+ features: viteFeatures.map((feature) => inspectFeature(ctx, feature, options[feature.name])),
696
+ root: ctx.root
697
+ };
698
+ }
699
+ async function getAddonsConfig(options = {}) {
700
+ const ctx = createAddonContext(options);
701
+ let combinedConfig = {};
702
+ for (const feature of viteFeatures) {
703
+ const inspection = inspectFeature(ctx, feature, options[feature.name]);
704
+ if (!inspection.enabled) {
705
+ continue;
706
+ }
707
+ const option = options[feature.name];
708
+ const configFragment = await resolveFeatureConfig(ctx, feature, option);
709
+ combinedConfig = mergeConfig(combinedConfig, configFragment);
710
+ }
711
+ return combinedConfig;
712
+ }
713
+
714
+ // src/config/base/index.ts
715
+ async function getBaseConfig(options = {}) {
716
+ const root = typeof options.viteConfig?.root === "string" ? options.viteConfig.root : process2.cwd();
717
+ const addonsConfig = await getAddonsConfig(options);
718
+ const rootConfig = {
719
+ resolve: {
720
+ alias: {
721
+ "@": path2.resolve(root, "src")
722
+ }
723
+ }
724
+ };
725
+ return mergeConfig2(rootConfig, addonsConfig);
726
+ }
727
+
728
+ // src/config/app.ts
729
+ function createAppConfig(config = {}) {
730
+ return defineConfig(async (env) => {
731
+ const userOptions = typeof config === "function" ? await config(env) : config;
732
+ const baseConfig = await getBaseConfig(userOptions);
733
+ const viteConfigExt = userOptions.viteConfig || {};
734
+ return mergeConfig3(baseConfig, viteConfigExt);
735
+ });
736
+ }
737
+
738
+ // src/config/lib.ts
739
+ import path3 from "path";
740
+ import process3 from "process";
741
+ import { detectDependencies as detectDependencies2 } from "@moluoxixi/core";
742
+ import { defineConfig as defineConfig2, mergeConfig as mergeConfig4 } from "vite";
743
+ function createDependencyExternal(dependencies) {
744
+ const uniqueDeps = Array.from(new Set(dependencies));
745
+ return (id) => uniqueDeps.some((dep) => id === dep || id.startsWith(`${dep}/`));
746
+ }
747
+ function resolveEntryPath(root, entry) {
748
+ return path3.isAbsolute(entry) ? entry : path3.resolve(root, entry);
749
+ }
750
+ function resolveLibEntry(root, entry) {
751
+ if (typeof entry === "string") {
752
+ return resolveEntryPath(root, entry);
753
+ }
754
+ if (Array.isArray(entry)) {
755
+ return entry.map((item) => resolveEntryPath(root, item));
756
+ }
757
+ return Object.fromEntries(
758
+ Object.entries(entry).map(([name, item]) => [name, resolveEntryPath(root, item)])
759
+ );
760
+ }
761
+ function createLibConfig(config = {}) {
762
+ return defineConfig2(async (env) => {
763
+ const userOptions = typeof config === "function" ? await config(env) : config;
764
+ const viteConfigExt = userOptions.viteConfig || {};
765
+ const root = typeof viteConfigExt.root === "string" ? viteConfigExt.root : process3.cwd();
766
+ const normalizedOptions = {
767
+ ...userOptions,
768
+ viteConfig: {
769
+ ...viteConfigExt,
770
+ root
771
+ }
772
+ };
773
+ const baseConfig = await getBaseConfig(normalizedOptions);
774
+ const { dependencies, optionalDependencies, peerDependencies } = detectDependencies2(root);
775
+ const libEntry = resolveLibEntry(root, userOptions.entry ?? "src/index.ts");
776
+ const external = createDependencyExternal([
777
+ ...Object.keys(dependencies),
778
+ ...Object.keys(optionalDependencies),
779
+ ...Object.keys(peerDependencies)
780
+ ]);
781
+ const libConfig = {
782
+ build: {
783
+ lib: {
784
+ entry: libEntry,
785
+ formats: ["es", "cjs"],
786
+ fileName: "index"
787
+ },
788
+ rollupOptions: {
789
+ external
790
+ }
791
+ }
792
+ };
793
+ return mergeConfig4(mergeConfig4(baseConfig, libConfig), viteConfigExt);
794
+ });
795
+ }
796
+ export {
797
+ createAppConfig,
798
+ createLibConfig,
799
+ defineAutoImportAddonOptions,
800
+ defineComponentsAddonOptions,
801
+ defineDevtoolsAddonOptions,
802
+ defineI18nAddonOptions,
803
+ defineMarkdownAddonOptions,
804
+ definePwaAddonOptions,
805
+ defineReactAddonOptions,
806
+ defineTailwindCssAddonOptions,
807
+ defineUnoCssAddonOptions,
808
+ defineViteSsgAddonOptions,
809
+ defineVitestAddonOptions,
810
+ defineVueAddonOptions,
811
+ defineVueLayoutsAddonOptions,
812
+ defineVueRouterAddonOptions,
813
+ getBaseConfig,
814
+ inspectViteFeatures
815
+ };