@vixt/vue 0.1.18 → 0.1.20

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,15 +1,61 @@
1
1
  import * as vite from 'vite';
2
2
  import * as _vixt_core from '@vixt/core';
3
- import { PluginOptions, VixtOptions } from '@vixt/core';
4
- import { RouterOptions } from 'vue-router';
3
+ import { Vixt, PluginOptions, VixtOptions } from '@vixt/core';
5
4
  import { PluginOptions as PluginOptions$1 } from 'pinia-plugin-persistedstate';
5
+ import { RouterOptions } from 'vue-router';
6
6
  import Vue from '@vitejs/plugin-vue';
7
- import Layouts from 'vite-plugin-vue-layouts';
8
- import Components from 'unplugin-vue-components/vite';
7
+ import UnoCSS from 'unocss/vite';
9
8
  import AutoImport from 'unplugin-auto-import/vite';
10
- import VueDevTools from 'vite-plugin-vue-devtools';
9
+ import Components from 'unplugin-vue-components/vite';
11
10
  import VueRouter from 'unplugin-vue-router/vite';
12
- import UnoCSS from 'unocss/vite';
11
+ import VueDevTools from 'vite-plugin-vue-devtools';
12
+ import Layouts from 'vite-plugin-vue-layouts';
13
+
14
+ type Property = Record<string, string>;
15
+ interface AppHead {
16
+ meta?: Property[];
17
+ link?: Property[];
18
+ style?: Property[];
19
+ script?: Property[];
20
+ title?: Property[];
21
+ noscript?: Property[];
22
+ }
23
+ interface AppOptions {
24
+ head?: AppHead;
25
+ /**
26
+ * @default /
27
+ */
28
+ baseURL?: string;
29
+ /**
30
+ * @default 'app'
31
+ */
32
+ rootId?: string;
33
+ /**
34
+ * @default 'div'
35
+ */
36
+ rootTag?: string;
37
+ /** inject css files */
38
+ css?: string[];
39
+ /**
40
+ * @default './loading.html'
41
+ */
42
+ loadingTemplate?: string;
43
+ }
44
+
45
+ declare function getAppComponentPath(vixt: Vixt): string | undefined;
46
+ declare function genarateAppComponent(vixt: Vixt): string;
47
+
48
+ declare function generateAppConfig(vixt: Vixt): string;
49
+
50
+ declare function generateCss(options: AppOptions): string;
51
+
52
+ declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
53
+
54
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
55
+
56
+ declare function generatePlugins(vixt: Vixt): string;
57
+
58
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
13
59
 
14
60
  declare module '@vixt/core' {
15
61
  interface VixtOptions {
@@ -41,4 +87,4 @@ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
41
87
 
42
88
  declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
43
89
 
44
- export { _default as default, presetVue };
90
+ export { type AppHead, type AppOptions, appVue, _default as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,61 @@
1
1
  import * as vite from 'vite';
2
2
  import * as _vixt_core from '@vixt/core';
3
- import { PluginOptions, VixtOptions } from '@vixt/core';
4
- import { RouterOptions } from 'vue-router';
3
+ import { Vixt, PluginOptions, VixtOptions } from '@vixt/core';
5
4
  import { PluginOptions as PluginOptions$1 } from 'pinia-plugin-persistedstate';
5
+ import { RouterOptions } from 'vue-router';
6
6
  import Vue from '@vitejs/plugin-vue';
7
- import Layouts from 'vite-plugin-vue-layouts';
8
- import Components from 'unplugin-vue-components/vite';
7
+ import UnoCSS from 'unocss/vite';
9
8
  import AutoImport from 'unplugin-auto-import/vite';
10
- import VueDevTools from 'vite-plugin-vue-devtools';
9
+ import Components from 'unplugin-vue-components/vite';
11
10
  import VueRouter from 'unplugin-vue-router/vite';
12
- import UnoCSS from 'unocss/vite';
11
+ import VueDevTools from 'vite-plugin-vue-devtools';
12
+ import Layouts from 'vite-plugin-vue-layouts';
13
+
14
+ type Property = Record<string, string>;
15
+ interface AppHead {
16
+ meta?: Property[];
17
+ link?: Property[];
18
+ style?: Property[];
19
+ script?: Property[];
20
+ title?: Property[];
21
+ noscript?: Property[];
22
+ }
23
+ interface AppOptions {
24
+ head?: AppHead;
25
+ /**
26
+ * @default /
27
+ */
28
+ baseURL?: string;
29
+ /**
30
+ * @default 'app'
31
+ */
32
+ rootId?: string;
33
+ /**
34
+ * @default 'div'
35
+ */
36
+ rootTag?: string;
37
+ /** inject css files */
38
+ css?: string[];
39
+ /**
40
+ * @default './loading.html'
41
+ */
42
+ loadingTemplate?: string;
43
+ }
44
+
45
+ declare function getAppComponentPath(vixt: Vixt): string | undefined;
46
+ declare function genarateAppComponent(vixt: Vixt): string;
47
+
48
+ declare function generateAppConfig(vixt: Vixt): string;
49
+
50
+ declare function generateCss(options: AppOptions): string;
51
+
52
+ declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
53
+
54
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
55
+
56
+ declare function generatePlugins(vixt: Vixt): string;
57
+
58
+ declare const appVue: _vixt_core.VixtModule<AppOptions>;
13
59
 
14
60
  declare module '@vixt/core' {
15
61
  interface VixtOptions {
@@ -41,4 +87,4 @@ declare const presetVue: _vixt_core.VixtModule<VixtOptions>;
41
87
 
42
88
  declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
43
89
 
44
- export { _default as default, presetVue };
90
+ export { type AppHead, type AppOptions, appVue, _default as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
package/dist/index.mjs CHANGED
@@ -1,13 +1,225 @@
1
1
  import { defineVixtModule, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
2
- import defu from 'defu';
2
+ import path from 'pathe';
3
+ import fs from 'fs-extra';
3
4
  import Vue from '@vitejs/plugin-vue';
4
- import Layouts from 'vite-plugin-vue-layouts';
5
- import Components from 'unplugin-vue-components/vite';
5
+ import defu from 'defu';
6
+ import UnoCSS from 'unocss/vite';
6
7
  import AutoImport from 'unplugin-auto-import/vite';
7
- import VueDevTools from 'vite-plugin-vue-devtools';
8
- import VueRouter from 'unplugin-vue-router/vite';
8
+ import Components from 'unplugin-vue-components/vite';
9
9
  import { VueRouterAutoImports } from 'unplugin-vue-router';
10
- import UnoCSS from 'unocss/vite';
10
+ import VueRouter from 'unplugin-vue-router/vite';
11
+ import VueDevTools from 'vite-plugin-vue-devtools';
12
+ import Layouts from 'vite-plugin-vue-layouts';
13
+
14
+ function getAppComponentPath(vixt) {
15
+ const { srcDirName } = vixt.options;
16
+ for (const layer of vixt._layers) {
17
+ const appComponentPath = path.resolve(layer.cwd, srcDirName, "App.vue");
18
+ if (fs.existsSync(appComponentPath))
19
+ return appComponentPath;
20
+ }
21
+ }
22
+ function genarateAppComponent(vixt) {
23
+ const appComponentPath = getAppComponentPath(vixt) || "@vixt/core/client/App.vue";
24
+ const appComponentTemplate = `import App from '${appComponentPath}'`;
25
+ return appComponentTemplate;
26
+ }
27
+
28
+ function generateAppConfig(vixt) {
29
+ const { buildImportsDir, srcDir, srcDirName } = 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.cwd, srcDirName, "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 appConfigTemplate = `
44
+ import { defu } from 'defu'
45
+ ${appConfigsImportTemplate}
46
+ const appConfig = defu(${appConfigsMergeTemplate}{})
47
+ function useAppConfig() {
48
+ return appConfig
49
+ }
50
+ export { useAppConfig }
51
+ `;
52
+ const mainTsPath = path.resolve(srcDir, "main.ts");
53
+ fs.outputFileSync(path.resolve(buildImportsDir, `app.config.ts`), `// @ts-nocheck
54
+ export { useAppConfig } from '${mainTsPath}'`);
55
+ return appConfigTemplate;
56
+ }
57
+
58
+ function generateCss(options) {
59
+ const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
60
+ return cssTemplate;
61
+ }
62
+
63
+ function resolveHeadTag(tag, attrs) {
64
+ const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
65
+ return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
66
+ }
67
+ function generateIndexHtml(options, vixt) {
68
+ const { buildDir, buildDirName, rootDir, srcDirName } = vixt.options;
69
+ const indexHtmlPath = path.resolve(rootDir, "index.html");
70
+ if (!fs.existsSync(indexHtmlPath))
71
+ fs.outputFileSync(indexHtmlPath, `<!-- Generated by Vixt -->
72
+ <!-- This file transform from '${buildDirName}/index.html' -->
73
+ `);
74
+ const { head = {}, rootTag, rootId } = options;
75
+ const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
76
+ const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
77
+ let { loadingTemplate = "" } = options;
78
+ if (!loadingTemplate) {
79
+ for (const layer of vixt._layers) {
80
+ const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
81
+ if (fs.existsSync(loadingTemplatePath)) {
82
+ loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
83
+ break;
84
+ }
85
+ }
86
+ }
87
+ const code = `<!DOCTYPE html>
88
+ <html>
89
+ <head>
90
+ ${headTemplate}
91
+ </head>
92
+ <body>
93
+ <${rootTag} id="${rootId}">
94
+ ${loadingTemplate}
95
+ </${rootTag}>
96
+ <script type="module" src="/${srcDirName}/main.ts"><\/script>
97
+ ${noscriptTemplate}
98
+ </body>
99
+ </html>
100
+ `;
101
+ fs.outputFileSync(path.resolve(buildDir, "index.html"), code);
102
+ return code;
103
+ }
104
+
105
+ function generatePlugins(vixt) {
106
+ const { srcDirName } = vixt.options;
107
+ let pluginsImportTemplate = "";
108
+ let pluginsMergeTemplate = "";
109
+ let i = 0;
110
+ for (const layer of [...vixt._layers].reverse()) {
111
+ const pluginsDir = path.resolve(layer.cwd, srcDirName, "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
+ function generateMainTs(options, vixt) {
135
+ const { buildDir, buildDirName, srcDir } = vixt.options;
136
+ const mainTsPath = path.resolve(srcDir, "main.ts");
137
+ if (!fs.existsSync(mainTsPath))
138
+ fs.outputFileSync(mainTsPath, `// Generated by Vixt
139
+ // This file transform from '${buildDirName}/main.ts'
140
+ `);
141
+ const appComponentTemplate = genarateAppComponent(vixt);
142
+ const cssTemplate = generateCss(options);
143
+ const appConfigTemplate = generateAppConfig(vixt);
144
+ const pluginsTemplate = generatePlugins(vixt);
145
+ const code = `// Generated by Vixt
146
+ // This file transform to '${srcDir}/main.ts'
147
+ // @ts-nocheck
148
+ ${appComponentTemplate}
149
+ ${cssTemplate}
150
+ ${appConfigTemplate}
151
+ ${pluginsTemplate}
152
+
153
+ import 'virtual:uno.css'
154
+ import { createApp } from 'vue'
155
+ import { createPinia } from 'pinia'
156
+ import { createPersistedState } from 'pinia-plugin-persistedstate'
157
+ import { createRouter, createWebHistory } from 'vue-router'
158
+ import { routes } from 'vue-router/auto-routes'
159
+ import { setupLayouts } from 'virtual:generated-layouts'
160
+
161
+ const pinia = createPinia()
162
+ pinia.use(createPersistedState(appConfig.piniaPersistedState))
163
+
164
+ const router = createRouter({
165
+ routes: setupLayouts(routes),
166
+ history: createWebHistory('${options.baseURL}'),
167
+ ...appConfig.router,
168
+ })
169
+
170
+ const app = createApp(App)
171
+ app.use(pinia).use(router)
172
+ usePlugins({ app, router, routes, pinia, appConfig })
173
+
174
+ app.mount('#${options.rootId}')
175
+ `;
176
+ fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
177
+ return code;
178
+ }
179
+
180
+ const name = "vixt:app";
181
+ const defaults$1 = {
182
+ rootId: "app",
183
+ rootTag: "div",
184
+ baseURL: "/",
185
+ css: [],
186
+ head: {
187
+ meta: [
188
+ { charset: "utf-8" },
189
+ { name: "viewport", content: "width=device-width, initial-scale=1" }
190
+ ]
191
+ }
192
+ };
193
+ const appVue = defineVixtModule({
194
+ meta: { name, configKey: "app" },
195
+ defaults: defaults$1,
196
+ setup(options, vixt) {
197
+ let indexHtmlCode;
198
+ let mainTsCode;
199
+ const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
200
+ return {
201
+ name,
202
+ configResolved() {
203
+ indexHtmlCode = generateIndexHtml(options, vixt);
204
+ mainTsCode = generateMainTs(options, vixt);
205
+ },
206
+ transformIndexHtml: {
207
+ order: "pre",
208
+ handler() {
209
+ return indexHtmlCode;
210
+ }
211
+ },
212
+ transform: {
213
+ order: "pre",
214
+ handler(_, id) {
215
+ if (id !== mainTsPath)
216
+ return;
217
+ return mainTsCode;
218
+ }
219
+ }
220
+ };
221
+ }
222
+ });
11
223
 
12
224
  const presetVue = defineVixtModule({
13
225
  async setup(_, vixt) {
@@ -47,37 +259,7 @@ const presetVue = defineVixtModule({
47
259
  });
48
260
 
49
261
  const defaults = {
50
- modules: [presetVue],
51
- app: {
52
- transformMain(code, vixt) {
53
- const { app } = vixt.options;
54
- code += `
55
- import 'virtual:uno.css'
56
- import { createApp } from 'vue'
57
- import { createPinia } from 'pinia'
58
- import { createPersistedState } from 'pinia-plugin-persistedstate'
59
- import { createRouter, createWebHistory } from 'vue-router'
60
- import { routes } from 'vue-router/auto-routes'
61
- import { setupLayouts } from 'virtual:generated-layouts'
62
-
63
- const pinia = createPinia()
64
- pinia.use(createPersistedState(appConfig.piniaPersistedState))
65
-
66
- const router = createRouter({
67
- routes: setupLayouts(routes),
68
- history: createWebHistory('${app.baseURL}'),
69
- ...appConfig.router,
70
- })
71
-
72
- const app = createApp(App)
73
- app.use(pinia).use(router)
74
- usePlugins({ app, router, routes, pinia, appConfig })
75
-
76
- app.mount('#${app.rootId}')
77
- `;
78
- return code;
79
- }
80
- },
262
+ modules: [appVue, presetVue],
81
263
  typescript: {
82
264
  tsConfig: {
83
265
  compilerOptions: {
@@ -88,4 +270,4 @@ app.mount('#${app.rootId}')
88
270
  };
89
271
  const index = createVixtPlugin({ defaults });
90
272
 
91
- export { index as default, presetVue };
273
+ export { appVue, index as default, genarateAppComponent, generateAppConfig, generateCss, generateIndexHtml, generateMainTs, generatePlugins, getAppComponentPath, presetVue };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/vue",
3
3
  "type": "module",
4
- "version": "0.1.18",
4
+ "version": "0.1.20",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -18,20 +18,20 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@vitejs/plugin-vue": "^5.1.3",
21
+ "@vitejs/plugin-vue": "^5.1.4",
22
22
  "@vitejs/plugin-vue-jsx": "^4.0.1",
23
- "@vueuse/core": "^11.0.3",
24
- "pinia": "^2.2.2",
25
- "pinia-plugin-persistedstate": "^4.0.0",
26
- "unocss": "0.61.6",
27
- "unplugin-auto-import": "^0.18.2",
23
+ "@vueuse/core": "^11.1.0",
24
+ "pinia": "^2.2.4",
25
+ "pinia-plugin-persistedstate": "^4.1.1",
26
+ "unocss": "^0.63.4",
27
+ "unplugin-auto-import": "^0.18.3",
28
28
  "unplugin-vue-components": "^0.27.4",
29
- "unplugin-vue-router": "^0.10.7",
30
- "vite-plugin-vue-devtools": "^7.4.4",
29
+ "unplugin-vue-router": "^0.10.8",
30
+ "vite-plugin-vue-devtools": "^7.4.6",
31
31
  "vite-plugin-vue-layouts": "^0.11.0",
32
- "vue": "^3.5.1",
33
- "vue-router": "^4.4.3",
34
- "@vixt/core": "0.1.18"
32
+ "vue": "^3.5.12",
33
+ "vue-router": "^4.4.5",
34
+ "@vixt/core": "0.1.20"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "unbuild"