@vixt/vue 0.3.6 → 0.4.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/index.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  import * as vite from 'vite';
2
2
  import * as _vixt_core from '@vixt/core';
3
- import { Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
4
5
  import { PluginOptions } from 'pinia-plugin-persistedstate';
5
- import { RouterOptions } from 'vue-router';
6
+ import { App } from 'vue';
7
+ import { RouterOptions, Router, RouteRecord } from 'vue-router';
6
8
  import Vue from '@vitejs/plugin-vue';
7
9
  import VueJsx from '@vitejs/plugin-vue-jsx';
8
10
  import UnoCSS from 'unocss/vite';
@@ -12,64 +14,29 @@ import VueRouter from 'unplugin-vue-router/vite';
12
14
  import VueDevTools from 'vite-plugin-vue-devtools';
13
15
  import Layouts from 'vite-plugin-vue-layouts';
14
16
 
15
- type Property = Record<string, string>;
16
- interface AppHead {
17
- meta?: Property[];
18
- link?: Property[];
19
- style?: Property[];
20
- script?: Property[];
21
- title?: Property[];
22
- noscript?: Property[];
23
- }
24
- interface AppOptions {
25
- head?: AppHead;
26
- /**
27
- * @default /
28
- */
29
- baseURL?: string;
30
- /**
31
- * @default 'app'
32
- */
33
- rootId?: string;
34
- /**
35
- * @default 'div'
36
- */
37
- rootTag?: string;
38
- /** inject css files */
39
- css?: string[];
40
- /**
41
- * @default './loading.html'
42
- */
43
- loadingTemplate?: string;
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
+ }
44
31
  }
45
32
 
33
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
34
+
46
35
  declare function getAppComponentPath(vixt: Vixt): string | undefined;
47
36
  declare function genarateAppComponent(vixt: Vixt): string;
48
37
 
49
- declare function generateAppConfig(vixt: Vixt): string;
50
-
51
- declare function generateCss(options: AppOptions): string;
52
-
53
- declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
54
-
55
38
  declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
56
39
 
57
- declare function generatePlugins(vixt: Vixt): string;
58
-
59
- declare module '@vixt/core' {
60
- interface VixtOptions {
61
- app?: AppOptions;
62
- }
63
- }
64
- declare module '@vixt/core/client' {
65
- interface VixtAppConfig {
66
- router?: Partial<RouterOptions>;
67
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
68
- piniaPersistedState?: PluginOptions;
69
- }
70
- }
71
- declare const appVue: _vixt_core.VixtModule<AppOptions>;
72
-
73
40
  declare module '@vixt/core' {
74
41
  interface VixtOptions {
75
42
  vue?: PluginOptions$1<typeof Vue>;
@@ -94,4 +61,4 @@ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
94
61
 
95
62
  declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
96
63
 
97
- export { type AppHead, type AppOptions, appVue, _default as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
64
+ export { appVue, _default as default, genarateAppComponent, generateMainTs, getAppComponentPath, presetVue };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import * as vite from 'vite';
2
2
  import * as _vixt_core from '@vixt/core';
3
- import { Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
4
5
  import { PluginOptions } from 'pinia-plugin-persistedstate';
5
- import { RouterOptions } from 'vue-router';
6
+ import { App } from 'vue';
7
+ import { RouterOptions, Router, RouteRecord } from 'vue-router';
6
8
  import Vue from '@vitejs/plugin-vue';
7
9
  import VueJsx from '@vitejs/plugin-vue-jsx';
8
10
  import UnoCSS from 'unocss/vite';
@@ -12,64 +14,29 @@ import VueRouter from 'unplugin-vue-router/vite';
12
14
  import VueDevTools from 'vite-plugin-vue-devtools';
13
15
  import Layouts from 'vite-plugin-vue-layouts';
14
16
 
15
- type Property = Record<string, string>;
16
- interface AppHead {
17
- meta?: Property[];
18
- link?: Property[];
19
- style?: Property[];
20
- script?: Property[];
21
- title?: Property[];
22
- noscript?: Property[];
23
- }
24
- interface AppOptions {
25
- head?: AppHead;
26
- /**
27
- * @default /
28
- */
29
- baseURL?: string;
30
- /**
31
- * @default 'app'
32
- */
33
- rootId?: string;
34
- /**
35
- * @default 'div'
36
- */
37
- rootTag?: string;
38
- /** inject css files */
39
- css?: string[];
40
- /**
41
- * @default './loading.html'
42
- */
43
- loadingTemplate?: string;
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
+ }
44
31
  }
45
32
 
33
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
34
+
46
35
  declare function getAppComponentPath(vixt: Vixt): string | undefined;
47
36
  declare function genarateAppComponent(vixt: Vixt): string;
48
37
 
49
- declare function generateAppConfig(vixt: Vixt): string;
50
-
51
- declare function generateCss(options: AppOptions): string;
52
-
53
- declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
54
-
55
38
  declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
56
39
 
57
- declare function generatePlugins(vixt: Vixt): string;
58
-
59
- declare module '@vixt/core' {
60
- interface VixtOptions {
61
- app?: AppOptions;
62
- }
63
- }
64
- declare module '@vixt/core/client' {
65
- interface VixtAppConfig {
66
- router?: Partial<RouterOptions>;
67
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
68
- piniaPersistedState?: PluginOptions;
69
- }
70
- }
71
- declare const appVue: _vixt_core.VixtModule<AppOptions>;
72
-
73
40
  declare module '@vixt/core' {
74
41
  interface VixtOptions {
75
42
  vue?: PluginOptions$1<typeof Vue>;
@@ -94,4 +61,4 @@ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
94
61
 
95
62
  declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
96
63
 
97
- export { type AppHead, type AppOptions, appVue, _default as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
64
+ export { appVue, _default as default, genarateAppComponent, generateMainTs, getAppComponentPath, presetVue };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineVixtModule, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
1
+ import { generateClient, generateCss, generateAppConfig, generatePlugins, defineVixtModule, generateIndexHtml, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
2
2
  import path from 'pathe';
3
3
  import fs from 'fs-extra';
4
4
  import Vue from '@vitejs/plugin-vue';
@@ -20,117 +20,17 @@ function getAppComponentPath(vixt) {
20
20
  }
21
21
  }
22
22
  function genarateAppComponent(vixt) {
23
- const appComponentPath = getAppComponentPath(vixt) || "@vixt/core/client/App.vue";
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;
24
30
  const appComponentTemplate = `import App from '${appComponentPath}'`;
25
31
  return appComponentTemplate;
26
32
  }
27
33
 
28
- function generateAppConfig(vixt) {
29
- const { buildImportsDir } = vixt.options;
30
- let appConfigsImportTemplate = "";
31
- let appConfigsMergeTemplate = "";
32
- let i = 0;
33
- for (const layer of vixt._layers) {
34
- const appConfigPath = path.resolve(layer.config.srcDir, "app.config.ts");
35
- if (fs.existsSync(appConfigPath)) {
36
- const appConfigName = `__app_config_${i}`;
37
- appConfigsImportTemplate += `import ${appConfigName} from '${appConfigPath}'
38
- `;
39
- appConfigsMergeTemplate += `${appConfigName}, `;
40
- i++;
41
- }
42
- }
43
- const globalAppConfigKey = "__VIXT_APP_CONFIG";
44
- const appConfigTemplate = `
45
- import { defu } from 'defu'
46
- ${appConfigsImportTemplate}
47
- const appConfig = defu(${appConfigsMergeTemplate}{})
48
- globalThis.${globalAppConfigKey} = appConfig
49
- `;
50
- fs.outputFileSync(path.resolve(buildImportsDir, `app.config.ts`), `// Generated by Vixt
51
- // @ts-nocheck
52
- import type { VixtAppConfig } from '@vixt/core/client'
53
-
54
- export const useAppConfig = () => globalThis.${globalAppConfigKey} as VixtAppConfig
55
- `);
56
- return appConfigTemplate;
57
- }
58
-
59
- function generateCss(options) {
60
- const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
61
- return cssTemplate;
62
- }
63
-
64
- function resolveHeadTag(tag, attrs) {
65
- const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
66
- return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
67
- }
68
- function generateIndexHtml(options, vixt) {
69
- const { buildDir, rootDir, srcDir } = vixt.options;
70
- const indexHtmlPath = path.resolve(rootDir, "index.html");
71
- if (!fs.existsSync(indexHtmlPath))
72
- fs.outputFileSync(indexHtmlPath, `<!-- Generated by Vixt -->
73
- <!-- This file transform from '${path.basename(buildDir)}/index.html' -->
74
- `);
75
- const { head = {}, rootTag, rootId } = options;
76
- const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
77
- const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
78
- let { loadingTemplate = "" } = options;
79
- if (!loadingTemplate) {
80
- for (const layer of vixt._layers) {
81
- const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
82
- if (fs.existsSync(loadingTemplatePath)) {
83
- loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
84
- break;
85
- }
86
- }
87
- }
88
- const code = `<!DOCTYPE html>
89
- <html>
90
- <head>
91
- ${headTemplate}
92
- </head>
93
- <body>
94
- <${rootTag} id="${rootId}">
95
- ${loadingTemplate}
96
- </${rootTag}>
97
- <script type="module" src="${srcDir.replace(rootDir, "")}/main.ts"><\/script>
98
- ${noscriptTemplate}
99
- </body>
100
- </html>
101
- `;
102
- fs.outputFileSync(path.resolve(buildDir, "index.html"), code);
103
- return code;
104
- }
105
-
106
- function generatePlugins(vixt) {
107
- let pluginsImportTemplate = "";
108
- let pluginsMergeTemplate = "";
109
- let i = 0;
110
- for (const layer of [...vixt._layers].reverse()) {
111
- const pluginsDir = path.resolve(layer.config.srcDir, "plugins");
112
- const files = fs.existsSync(pluginsDir) ? fs.readdirSync(pluginsDir) : [];
113
- for (const f of files) {
114
- const p = path.resolve(pluginsDir, f);
115
- const pluginName = `__plugin_${i}`;
116
- pluginsImportTemplate += `import ${pluginName} from '${p}'
117
- `;
118
- pluginsMergeTemplate += `${pluginName}, `;
119
- i++;
120
- }
121
- }
122
- const pluginsTemplate = `
123
- ${pluginsImportTemplate}
124
- const plugins = [${pluginsMergeTemplate}]
125
- function usePlugins(options) {
126
- for (const plugin of plugins) {
127
- typeof plugin === 'function' && plugin(options)
128
- }
129
- }
130
- `;
131
- return pluginsTemplate;
132
- }
133
-
134
34
  function generateMainTs(options, vixt) {
135
35
  const { buildDir, srcDir } = vixt.options;
136
36
  const mainTsPath = path.resolve(srcDir, "main.ts");
@@ -138,6 +38,7 @@ function generateMainTs(options, vixt) {
138
38
  fs.outputFileSync(mainTsPath, `// Generated by Vixt
139
39
  // This file transform from '${path.basename(buildDir)}/main.ts'
140
40
  `);
41
+ generateClient(vixt);
141
42
  const appComponentTemplate = genarateAppComponent(vixt);
142
43
  const cssTemplate = generateCss(options);
143
44
  const appConfigTemplate = generateAppConfig(vixt);
@@ -177,11 +78,12 @@ app.mount('#${options.rootId}')
177
78
  return code;
178
79
  }
179
80
 
180
- const name = "vixt:app";
81
+ const name$1 = "vixt:app-vue";
181
82
  const defaults$1 = {
182
83
  rootId: "app",
183
84
  rootTag: "div",
184
85
  baseURL: "/",
86
+ entryFile: "main.ts",
185
87
  css: [],
186
88
  head: {
187
89
  meta: [
@@ -191,14 +93,14 @@ const defaults$1 = {
191
93
  }
192
94
  };
193
95
  const appVue = defineVixtModule({
194
- meta: { name, configKey: "app" },
96
+ meta: { name: name$1, configKey: "app" },
195
97
  defaults: defaults$1,
196
98
  setup(options, vixt) {
197
99
  let indexHtmlCode;
198
100
  let mainTsCode;
199
101
  const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
200
102
  return {
201
- name,
103
+ name: name$1,
202
104
  configResolved() {
203
105
  indexHtmlCode = generateIndexHtml(options, vixt);
204
106
  mainTsCode = generateMainTs(options, vixt);
@@ -221,35 +123,52 @@ const appVue = defineVixtModule({
221
123
  }
222
124
  });
223
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";
224
140
  const presetVue = defineVixtModule({
141
+ meta: { name },
225
142
  async setup(_, vixt) {
226
- const { components = [], composables = [], constants = [], utils = [], stores = [], pages = [], layouts = [] } = resolveLayersDirs(vixt._layers);
143
+ const { components = [], composables = [], constants = [], utils = [], stores = [], pages = [], layouts = [] } = resolveLayersDirs([...vixt._layers].reverse());
227
144
  const { buildTypesDir, buildImportsDir } = vixt.options;
228
145
  const defaultOptions = {
229
146
  vue: {},
230
147
  vueJsx: {},
231
148
  router: {
232
149
  dts: `${buildTypesDir}/typed-router.d.ts`,
233
- routesFolder: pages,
150
+ routesFolder: pages
234
151
  /** Fix overrides priority */
235
- extendRoute(route) {
236
- const node = route.node.value;
237
- const overrides = node._overrides;
238
- if (overrides.size <= 1)
239
- return;
240
- for (const pageDir of pages) {
241
- const matched = [...overrides.keys()].find((e) => e.match(pageDir));
242
- if (matched) {
243
- node.components.set("default", matched);
244
- return;
245
- }
246
- }
247
- }
152
+ // extendRoute(route) {
153
+ // // @ts-ignore
154
+ // const node: TreeNode['value'] = route.node.value
155
+ // // @ts-ignore
156
+ // const overrides: Map<string, object> = node._overrides
157
+ // if (overrides.size <= 1)
158
+ // return
159
+ // for (const pageDir of [...pages].reverse()) {
160
+ // const matched = [...overrides.keys()].find(e => e.match(pageDir))
161
+ // if (matched) {
162
+ // node.components.set('default', matched)
163
+ // return
164
+ // }
165
+ // }
166
+ // },
248
167
  },
249
- layouts: { layoutsDirs: [...layouts].reverse(), pagesDirs: pages },
168
+ layouts: { layoutsDirs: layouts, pagesDirs: pages },
250
169
  components: {
251
170
  dts: `${buildTypesDir}/components.d.ts`,
252
- dirs: components,
171
+ dirs: [...components].reverse(),
253
172
  directoryAsNamespace: true,
254
173
  collapseSamePrefixes: true
255
174
  },
@@ -263,6 +182,7 @@ const presetVue = defineVixtModule({
263
182
  devtools: { enabled: false }
264
183
  };
265
184
  const options = vixt.options = defu(vixt.options, defaultOptions);
185
+ genarateGlobalComponents(vixt);
266
186
  const plugins = [
267
187
  VueRouter(options.router),
268
188
  Vue(options.vue),
@@ -289,4 +209,4 @@ const defaults = {
289
209
  };
290
210
  const index = createVixtPlugin({ defaults });
291
211
 
292
- export { appVue, index as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
212
+ 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.3.6",
4
+ "version": "0.4.1",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -18,23 +18,25 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@vitejs/plugin-vue": "^5.2.3",
22
- "@vitejs/plugin-vue-jsx": "^4.1.2",
23
- "@vue/compiler-sfc": "^3.5.13",
24
- "@vueuse/core": "^13.1.0",
21
+ "@vitejs/plugin-vue": "^5.2.4",
22
+ "@vitejs/plugin-vue-jsx": "^4.2.0",
23
+ "@vue/compiler-sfc": "^3.5.14",
24
+ "@vueuse/core": "^13.2.0",
25
25
  "pinia": "^3.0.2",
26
- "pinia-plugin-persistedstate": "^4.2.0",
26
+ "pinia-plugin-persistedstate": "^4.3.0",
27
27
  "unocss": "66.0.0",
28
28
  "unplugin-auto-import": "^19.2.0",
29
29
  "unplugin-vue-components": "28.0.0",
30
30
  "unplugin-vue-router": "^0.12.0",
31
31
  "vite-plugin-vue-devtools": "^7.7.6",
32
32
  "vite-plugin-vue-layouts": "^0.11.0",
33
- "vue": "^3.5.13",
33
+ "vue": "^3.5.14",
34
34
  "vue-router": "^4.5.1",
35
- "@vixt/core": "0.3.6"
35
+ "vue-tsc": "^2.2.10",
36
+ "@vixt/core": "0.4.1"
36
37
  },
37
38
  "scripts": {
38
- "build": "unbuild"
39
+ "build": "unbuild",
40
+ "dev": "unbuild --stub"
39
41
  }
40
42
  }