@vixt/vue 0.0.2 → 0.0.4

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.
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import { VixtOptions } from '@vixt/core';
3
+
4
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
5
+
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import { VixtOptions } from '@vixt/core';
3
+
4
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
5
+
6
+ export { _default as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,129 @@
1
+ import { defineVixtModule, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
2
+ import path from 'pathe';
3
+ import fs from 'fs-extra';
4
+ import defu from 'defu';
5
+ import Vue from '@vitejs/plugin-vue';
6
+ import Layouts from 'vite-plugin-vue-layouts';
7
+ import Components from 'unplugin-vue-components/vite';
8
+ import AutoImport from 'unplugin-auto-import/vite';
9
+ import VueDevTools from 'vite-plugin-vue-devtools';
10
+ import VueRouter from 'unplugin-vue-router/vite';
11
+ import { VueRouterAutoImports } from 'unplugin-vue-router';
12
+ import UnoCSS from 'unocss/vite';
13
+
14
+ function resolveLayersPlugins(layers, from) {
15
+ const { plugins = [] } = resolveLayersDirs(layers);
16
+ return plugins.map((pluginPath) => {
17
+ const pluginsDir = path.relative(from, pluginPath);
18
+ return `${pluginsDir}/*.ts`;
19
+ });
20
+ }
21
+ function generateMainTs(options, vixt, config) {
22
+ const { buildDir } = vixt.options;
23
+ const { rootId } = options;
24
+ const layersPluginsPath = resolveLayersPlugins(vixt._layers, path.join(config.root, buildDir));
25
+ const baseURL = options?.baseURL ?? config.env.BASE_URL ?? "/";
26
+ const cssTemplate = options?.css?.map((e) => `import '${e}'`).join("\n");
27
+ const code = `/** Generated by Vixt */
28
+ // @ts-nocheck
29
+ import { createApp } from 'vue'
30
+ import { createRouter, createWebHistory } from 'vue-router'
31
+ import { routes } from 'vue-router/auto-routes'
32
+ import { setupLayouts } from 'virtual:generated-layouts'
33
+ import { createPinia } from 'pinia'
34
+ import { createPersistedState } from 'pinia-plugin-persistedstate'
35
+ import App from '@/App.vue'
36
+
37
+ ${cssTemplate}
38
+
39
+ const pinia = createPinia()
40
+ pinia.use(createPersistedState())
41
+
42
+ const router = createRouter({
43
+ routes: setupLayouts(routes),
44
+ history: createWebHistory('${baseURL}'),
45
+ })
46
+
47
+ const app = createApp(App)
48
+ app.use(pinia).use(router)
49
+ // install all plugins under 'plugins/'
50
+ const plugins = import.meta.glob(${JSON.stringify(layersPluginsPath)}, { import: 'default', eager: true })
51
+ // @ts-ignore
52
+ Object.values(plugins).forEach((plugin) => typeof plugin === 'function' && plugin({ app, router, routes, pinia }))
53
+
54
+ app.mount('#${rootId}')
55
+ `;
56
+ fs.outputFileSync(path.resolve(config.root, `${buildDir}/main.ts`), code);
57
+ return code;
58
+ }
59
+ const name = "vixt:entry";
60
+ const defaults$1 = {
61
+ rootId: "app",
62
+ css: ["virtual:uno.css"]
63
+ };
64
+ const entry = defineVixtModule({
65
+ meta: { name, configKey: "app" },
66
+ defaults: defaults$1,
67
+ setup(options, vixt) {
68
+ return {
69
+ name: "vixt:entry",
70
+ configResolved(config) {
71
+ generateMainTs(options, vixt, config);
72
+ }
73
+ };
74
+ }
75
+ });
76
+
77
+ const presetVue = defineVixtModule({
78
+ async setup(_, vixt) {
79
+ const { components, composables = [], constants = [], utils = [], stores = [], pages, layouts } = resolveLayersDirs(vixt._layers);
80
+ const { buildTypesDir } = vixt.options;
81
+ const defaultOptions = {
82
+ vue: {},
83
+ router: { dts: `${buildTypesDir}/typed-router.d.ts`, routesFolder: pages },
84
+ layouts: { layoutsDirs: layouts, pagesDirs: pages },
85
+ components: {
86
+ dts: `${buildTypesDir}/components.d.ts`,
87
+ dirs: components,
88
+ directoryAsNamespace: true,
89
+ collapseSamePrefixes: true,
90
+ allowOverrides: true
91
+ },
92
+ imports: {
93
+ imports: ["vue", "@vueuse/core", "pinia", VueRouterAutoImports],
94
+ dts: `${buildTypesDir}/auto-imports.d.ts`,
95
+ dirs: [...composables, ...constants, ...stores, ...utils],
96
+ vueTemplate: true
97
+ },
98
+ unocss: {},
99
+ devtools: {}
100
+ };
101
+ const options = defu(vixt.options, defaultOptions);
102
+ const plugins = [
103
+ VueRouter(options.router),
104
+ Vue(options.vue),
105
+ Layouts(options.layouts),
106
+ Components(options.components),
107
+ AutoImport(options.imports),
108
+ UnoCSS(options.unocss),
109
+ VueDevTools(options.devtools)
110
+ ];
111
+ return plugins;
112
+ }
113
+ });
114
+
115
+ const defaults = {
116
+ modules: [entry, presetVue],
117
+ app: {
118
+ head: {
119
+ link: [{ rel: "icon", href: "/favicon.ico" }]
120
+ }
121
+ },
122
+ typescript: {
123
+ references: ["types/typed-router.d.ts", "types/components.d.ts", "types/auto-imports.d.ts", "types/vite-env.d.ts"],
124
+ tsConfig: { compilerOptions: { types: ["vite-plugin-vue-layouts/client", "unplugin-vue-router/client"] } }
125
+ }
126
+ };
127
+ const index = createVixtPlugin({ defaults });
128
+
129
+ export { index as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/vue",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -31,7 +31,7 @@
31
31
  "vite-plugin-vue-layouts": "^0.11.0",
32
32
  "vue": "^3.4.31",
33
33
  "vue-router": "^4.4.0",
34
- "@vixt/core": "0.0.2"
34
+ "@vixt/core": "0.0.4"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "unbuild"