@vixt/vue 0.4.0 → 0.4.2

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,64 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
5
+ import { PluginOptions } from 'pinia-plugin-persistedstate';
6
+ import { App } from 'vue';
7
+ import { RouterOptions, Router, RouteRecord } from 'vue-router';
8
+ import Vue from '@vitejs/plugin-vue';
9
+ import VueJsx from '@vitejs/plugin-vue-jsx';
10
+ import UnoCSS from 'unocss/vite';
11
+ import AutoImport from 'unplugin-auto-import/vite';
12
+ import Components from 'unplugin-vue-components/vite';
13
+ import VueRouter from 'unplugin-vue-router/vite';
14
+ import VueDevTools from 'vite-plugin-vue-devtools';
15
+ import Layouts from 'vite-plugin-vue-layouts';
16
+
17
+ declare module '@vixt/core/client' {
18
+ interface VixtAppConfig {
19
+ router?: Partial<RouterOptions>
20
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
21
+ piniaPersistedState?: PluginOptions
22
+ }
23
+
24
+ interface VixtApp {
25
+ app: App
26
+ router: Router
27
+ routes: RouteRecord[]
28
+ pinia: Pinia
29
+ appConfig: VixtAppConfig
30
+ }
31
+ }
32
+
33
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
34
+
35
+ declare function getAppComponentPath(vixt: Vixt): string | undefined;
36
+ declare function genarateAppComponent(vixt: Vixt): string;
37
+
38
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
39
+
40
+ declare module '@vixt/core' {
41
+ interface VixtOptions {
42
+ vue?: PluginOptions$1<typeof Vue>;
43
+ vueJsx?: PluginOptions$1<typeof VueJsx>;
44
+ /** https://github.com/posva/unplugin-vue-router */
45
+ router?: PluginOptions$1<typeof VueRouter>;
46
+ /** https://github.com/JohnCampionJr/vite-plugin-vue-layouts */
47
+ layouts?: PluginOptions$1<typeof Layouts>;
48
+ /** https://github.com/unplugin/unplugin-vue-components */
49
+ components?: PluginOptions$1<typeof Components>;
50
+ /** https://github.com/unplugin/unplugin-auto-import */
51
+ imports?: PluginOptions$1<typeof AutoImport>;
52
+ /** https://github.com/unocss/unocss */
53
+ unocss?: PluginOptions$1<typeof UnoCSS>;
54
+ /** https://github.com/webfansplz/vite-plugin-vue-devtools */
55
+ devtools?: PluginOptions$1<typeof VueDevTools> & {
56
+ enabled?: boolean;
57
+ };
58
+ }
59
+ }
60
+ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
61
+
62
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
63
+
64
+ export { appVue, _default as default, genarateAppComponent, generateMainTs, getAppComponentPath, presetVue };
@@ -0,0 +1,64 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
5
+ import { PluginOptions } from 'pinia-plugin-persistedstate';
6
+ import { App } from 'vue';
7
+ import { RouterOptions, Router, RouteRecord } from 'vue-router';
8
+ import Vue from '@vitejs/plugin-vue';
9
+ import VueJsx from '@vitejs/plugin-vue-jsx';
10
+ import UnoCSS from 'unocss/vite';
11
+ import AutoImport from 'unplugin-auto-import/vite';
12
+ import Components from 'unplugin-vue-components/vite';
13
+ import VueRouter from 'unplugin-vue-router/vite';
14
+ import VueDevTools from 'vite-plugin-vue-devtools';
15
+ import Layouts from 'vite-plugin-vue-layouts';
16
+
17
+ declare module '@vixt/core/client' {
18
+ interface VixtAppConfig {
19
+ router?: Partial<RouterOptions>
20
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
21
+ piniaPersistedState?: PluginOptions
22
+ }
23
+
24
+ interface VixtApp {
25
+ app: App
26
+ router: Router
27
+ routes: RouteRecord[]
28
+ pinia: Pinia
29
+ appConfig: VixtAppConfig
30
+ }
31
+ }
32
+
33
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
34
+
35
+ declare function getAppComponentPath(vixt: Vixt): string | undefined;
36
+ declare function genarateAppComponent(vixt: Vixt): string;
37
+
38
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
39
+
40
+ declare module '@vixt/core' {
41
+ interface VixtOptions {
42
+ vue?: PluginOptions$1<typeof Vue>;
43
+ vueJsx?: PluginOptions$1<typeof VueJsx>;
44
+ /** https://github.com/posva/unplugin-vue-router */
45
+ router?: PluginOptions$1<typeof VueRouter>;
46
+ /** https://github.com/JohnCampionJr/vite-plugin-vue-layouts */
47
+ layouts?: PluginOptions$1<typeof Layouts>;
48
+ /** https://github.com/unplugin/unplugin-vue-components */
49
+ components?: PluginOptions$1<typeof Components>;
50
+ /** https://github.com/unplugin/unplugin-auto-import */
51
+ imports?: PluginOptions$1<typeof AutoImport>;
52
+ /** https://github.com/unocss/unocss */
53
+ unocss?: PluginOptions$1<typeof UnoCSS>;
54
+ /** https://github.com/webfansplz/vite-plugin-vue-devtools */
55
+ devtools?: PluginOptions$1<typeof VueDevTools> & {
56
+ enabled?: boolean;
57
+ };
58
+ }
59
+ }
60
+ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
61
+
62
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
63
+
64
+ export { appVue, _default as default, genarateAppComponent, generateMainTs, getAppComponentPath, presetVue };
package/dist/index.mjs ADDED
@@ -0,0 +1,210 @@
1
+ import { generateClient, generateCss, generateAppConfig, generatePlugins, defineVixtModule, generateIndexHtml, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
2
+ import path from 'pathe';
3
+ import fs from 'fs-extra';
4
+ import Vue from '@vitejs/plugin-vue';
5
+ import VueJsx from '@vitejs/plugin-vue-jsx';
6
+ import defu from 'defu';
7
+ import UnoCSS from 'unocss/vite';
8
+ import AutoImport from 'unplugin-auto-import/vite';
9
+ import Components from 'unplugin-vue-components/vite';
10
+ import { VueRouterAutoImports } from 'unplugin-vue-router';
11
+ import VueRouter from 'unplugin-vue-router/vite';
12
+ import VueDevTools from 'vite-plugin-vue-devtools';
13
+ import Layouts from 'vite-plugin-vue-layouts';
14
+
15
+ function getAppComponentPath(vixt) {
16
+ for (const layer of vixt._layers) {
17
+ const appComponentPath = path.resolve(layer.config.srcDir, "App.vue");
18
+ if (fs.existsSync(appComponentPath))
19
+ return appComponentPath;
20
+ }
21
+ }
22
+ function genarateAppComponent(vixt) {
23
+ const { buildDir } = vixt.options;
24
+ const defaultAppComponentPath = path.resolve(buildDir, `App.vue`);
25
+ fs.outputFileSync(defaultAppComponentPath, `<template>
26
+ <RouterView />
27
+ </template>
28
+ `);
29
+ const appComponentPath = getAppComponentPath(vixt) || defaultAppComponentPath;
30
+ const appComponentTemplate = `import App from '${appComponentPath}'`;
31
+ return appComponentTemplate;
32
+ }
33
+
34
+ function generateMainTs(options, vixt) {
35
+ const { buildDir, srcDir } = vixt.options;
36
+ const mainTsPath = path.resolve(srcDir, "main.ts");
37
+ if (!fs.existsSync(mainTsPath))
38
+ fs.outputFileSync(mainTsPath, `// Generated by Vixt
39
+ // This file transform from '${path.basename(buildDir)}/main.ts'
40
+ `);
41
+ generateClient(vixt);
42
+ const appComponentTemplate = genarateAppComponent(vixt);
43
+ const cssTemplate = generateCss(options);
44
+ const appConfigTemplate = generateAppConfig(vixt);
45
+ const pluginsTemplate = generatePlugins(vixt);
46
+ const code = `// Generated by Vixt
47
+ // This file transform to '${srcDir}/main.ts'
48
+ // @ts-nocheck
49
+ ${appComponentTemplate}
50
+ ${cssTemplate}
51
+ ${appConfigTemplate}
52
+ ${pluginsTemplate}
53
+
54
+ import 'virtual:uno.css'
55
+ import { createApp } from 'vue'
56
+ import { createPinia } from 'pinia'
57
+ import { createPersistedState } from 'pinia-plugin-persistedstate'
58
+ import { createRouter, createWebHistory } from 'vue-router'
59
+ import { routes } from 'vue-router/auto-routes'
60
+ import { setupLayouts } from 'virtual:generated-layouts'
61
+
62
+ const pinia = createPinia()
63
+ pinia.use(createPersistedState(appConfig.piniaPersistedState))
64
+
65
+ const router = createRouter({
66
+ routes: setupLayouts(routes),
67
+ history: createWebHistory('${options.baseURL}'),
68
+ ...appConfig.router,
69
+ })
70
+
71
+ const app = createApp(App)
72
+ app.use(pinia).use(router)
73
+ usePlugins({ app, router, routes, pinia, appConfig })
74
+
75
+ app.mount('#${options.rootId}')
76
+ `;
77
+ fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
78
+ return code;
79
+ }
80
+
81
+ const name$1 = "vixt:app-vue";
82
+ const defaults$1 = {
83
+ rootId: "app",
84
+ rootTag: "div",
85
+ baseURL: "/",
86
+ entryFile: "main.ts",
87
+ css: [],
88
+ head: {
89
+ meta: [
90
+ { charset: "utf-8" },
91
+ { name: "viewport", content: "width=device-width, initial-scale=1" }
92
+ ]
93
+ }
94
+ };
95
+ const appVue = defineVixtModule({
96
+ meta: { name: name$1, configKey: "app" },
97
+ defaults: defaults$1,
98
+ setup(options, vixt) {
99
+ let indexHtmlCode;
100
+ let mainTsCode;
101
+ const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
102
+ return {
103
+ name: name$1,
104
+ configResolved() {
105
+ indexHtmlCode = generateIndexHtml(options, vixt);
106
+ mainTsCode = generateMainTs(options, vixt);
107
+ },
108
+ transformIndexHtml: {
109
+ order: "pre",
110
+ handler() {
111
+ return indexHtmlCode;
112
+ }
113
+ },
114
+ transform: {
115
+ order: "pre",
116
+ handler(_, id) {
117
+ if (id !== mainTsPath)
118
+ return;
119
+ return mainTsCode;
120
+ }
121
+ }
122
+ };
123
+ }
124
+ });
125
+
126
+ function genarateGlobalComponents(vixt) {
127
+ const { buildTypesDir } = vixt.options;
128
+ const codePath = path.resolve(buildTypesDir, "global-components.d.ts");
129
+ const code = `
130
+ import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
131
+
132
+ declare module 'vue'{
133
+ interface GlobalComponents extends _GlobalComponents {}
134
+ }
135
+ `;
136
+ fs.outputFileSync(codePath, code);
137
+ }
138
+
139
+ const name = "vixt:preset-vue";
140
+ const presetVue = defineVixtModule({
141
+ meta: { name },
142
+ async setup(_, vixt) {
143
+ const { components = [], composables = [], constants = [], utils = [], stores = [], pages = [], layouts = [] } = resolveLayersDirs([...vixt._layers].reverse());
144
+ const { buildTypesDir, buildImportsDir } = vixt.options;
145
+ const defaultOptions = {
146
+ vue: {},
147
+ vueJsx: {},
148
+ router: {
149
+ dts: `${buildTypesDir}/typed-router.d.ts`,
150
+ routesFolder: pages,
151
+ /** Fix overrides priority */
152
+ extendRoute(route) {
153
+ const node = route.node.value;
154
+ const overrides = node._overrides;
155
+ if (overrides.size <= 1)
156
+ return;
157
+ for (const pageDir of [...pages].reverse()) {
158
+ const matched = [...overrides.keys()].find((e) => e.match(pageDir));
159
+ if (matched) {
160
+ node.components.set("default", matched);
161
+ return;
162
+ }
163
+ }
164
+ }
165
+ },
166
+ layouts: { layoutsDirs: layouts, pagesDirs: pages },
167
+ components: {
168
+ dts: `${buildTypesDir}/components.d.ts`,
169
+ dirs: [...components].reverse(),
170
+ directoryAsNamespace: true,
171
+ collapseSamePrefixes: true
172
+ },
173
+ imports: {
174
+ imports: ["vue", "@vueuse/core", "pinia", VueRouterAutoImports],
175
+ dts: `${buildTypesDir}/auto-imports.d.ts`,
176
+ dirs: [composables, constants, stores, utils, buildImportsDir].flat(),
177
+ vueTemplate: true
178
+ },
179
+ unocss: {},
180
+ devtools: { enabled: false }
181
+ };
182
+ const options = vixt.options = defu(vixt.options, defaultOptions);
183
+ genarateGlobalComponents(vixt);
184
+ const plugins = [
185
+ VueRouter(options.router),
186
+ Vue(options.vue),
187
+ VueJsx(options.vueJsx),
188
+ Layouts(options.layouts),
189
+ Components(options.components),
190
+ AutoImport(options.imports),
191
+ UnoCSS(options.unocss),
192
+ options.devtools?.enabled && VueDevTools(options.devtools)
193
+ ];
194
+ return plugins;
195
+ }
196
+ });
197
+
198
+ const defaults = {
199
+ modules: [appVue, presetVue],
200
+ typescript: {
201
+ tsConfig: {
202
+ compilerOptions: {
203
+ types: ["vite-plugin-vue-layouts/client", "unplugin-vue-router/client"]
204
+ }
205
+ }
206
+ }
207
+ };
208
+ const index = createVixtPlugin({ defaults });
209
+
210
+ export { appVue, index as default, genarateAppComponent, generateMainTs, getAppComponentPath, presetVue };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/vue",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -20,7 +20,6 @@
20
20
  "dependencies": {
21
21
  "@vitejs/plugin-vue": "^5.2.4",
22
22
  "@vitejs/plugin-vue-jsx": "^4.2.0",
23
- "@vue/compiler-sfc": "^3.5.14",
24
23
  "@vueuse/core": "^13.2.0",
25
24
  "pinia": "^3.0.2",
26
25
  "pinia-plugin-persistedstate": "^4.3.0",
@@ -33,7 +32,7 @@
33
32
  "vue": "^3.5.14",
34
33
  "vue-router": "^4.5.1",
35
34
  "vue-tsc": "^2.2.10",
36
- "@vixt/core": "0.4.0"
35
+ "@vixt/core": "0.4.2"
37
36
  },
38
37
  "scripts": {
39
38
  "build": "unbuild",