@vixt/uni 0.1.17 → 0.1.19

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,19 @@
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 { PersistedStateFactoryOptions } from 'pinia-plugin-unistorage';
3
+ import { Vixt, PluginOptions, VixtOptions } from '@vixt/core';
4
+ import { AppOptions } from '@vixt/vue';
5
+ import { PluginOptions as PluginOptions$1 } from 'pinia-plugin-persistedstate';
5
6
  import Uni from '@dcloudio/vite-plugin-uni';
6
- import Pages from '@uni-helper/vite-plugin-uni-pages';
7
- import Layouts from '@uni-helper/vite-plugin-uni-layouts';
8
7
  import Components from '@uni-helper/vite-plugin-uni-components';
9
- import AutoImport from 'unplugin-auto-import/vite';
8
+ import Layouts from '@uni-helper/vite-plugin-uni-layouts';
9
+ import Pages from '@uni-helper/vite-plugin-uni-pages';
10
10
  import UnoCSS from 'unocss/vite';
11
+ import AutoImport from 'unplugin-auto-import/vite';
11
12
  import { ImportsMap } from 'unplugin-auto-import/types';
12
13
 
14
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
15
+ declare const appUni: _vixt_core.VixtModule<AppOptions>;
16
+
13
17
  declare module '@vixt/core' {
14
18
  interface VixtOptions {
15
19
  uni?: PluginOptions<typeof Uni>;
@@ -27,8 +31,8 @@ declare module '@vixt/core' {
27
31
  }
28
32
  declare module '@vixt/core/client' {
29
33
  interface VixtAppConfig {
30
- /** https://github.com/dishait/pinia-plugin-unistorage */
31
- piniaPersistedState?: PersistedStateFactoryOptions;
34
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
35
+ piniaPersistedState?: PluginOptions$1;
32
36
  }
33
37
  }
34
38
  declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
@@ -43,4 +47,4 @@ declare function useImports(): ImportsMap;
43
47
 
44
48
  declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
45
49
 
46
- export { _default as default, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
50
+ export { appUni, _default as default, generateMainTs, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,19 @@
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 { PersistedStateFactoryOptions } from 'pinia-plugin-unistorage';
3
+ import { Vixt, PluginOptions, VixtOptions } from '@vixt/core';
4
+ import { AppOptions } from '@vixt/vue';
5
+ import { PluginOptions as PluginOptions$1 } from 'pinia-plugin-persistedstate';
5
6
  import Uni from '@dcloudio/vite-plugin-uni';
6
- import Pages from '@uni-helper/vite-plugin-uni-pages';
7
- import Layouts from '@uni-helper/vite-plugin-uni-layouts';
8
7
  import Components from '@uni-helper/vite-plugin-uni-components';
9
- import AutoImport from 'unplugin-auto-import/vite';
8
+ import Layouts from '@uni-helper/vite-plugin-uni-layouts';
9
+ import Pages from '@uni-helper/vite-plugin-uni-pages';
10
10
  import UnoCSS from 'unocss/vite';
11
+ import AutoImport from 'unplugin-auto-import/vite';
11
12
  import { ImportsMap } from 'unplugin-auto-import/types';
12
13
 
14
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
15
+ declare const appUni: _vixt_core.VixtModule<AppOptions>;
16
+
13
17
  declare module '@vixt/core' {
14
18
  interface VixtOptions {
15
19
  uni?: PluginOptions<typeof Uni>;
@@ -27,8 +31,8 @@ declare module '@vixt/core' {
27
31
  }
28
32
  declare module '@vixt/core/client' {
29
33
  interface VixtAppConfig {
30
- /** https://github.com/dishait/pinia-plugin-unistorage */
31
- piniaPersistedState?: PersistedStateFactoryOptions;
34
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
35
+ piniaPersistedState?: PluginOptions$1;
32
36
  }
33
37
  }
34
38
  declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
@@ -43,4 +47,4 @@ declare function useImports(): ImportsMap;
43
47
 
44
48
  declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
45
49
 
46
- export { _default as default, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
50
+ export { appUni, _default as default, generateMainTs, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
package/dist/index.mjs CHANGED
@@ -1,17 +1,107 @@
1
1
  import { defineVixtModule, resolveLayersDirs, defineVitePlugin, createVixtPlugin } from '@vixt/core';
2
- import defu from 'defu';
2
+ import { generateIndexHtml, genarateAppComponent, generateCss, generateAppConfig, generatePlugins } from '@vixt/vue';
3
+ import fs from 'fs-extra';
4
+ import path from 'pathe';
3
5
  import Uni from '@dcloudio/vite-plugin-uni';
4
- import Pages from '@uni-helper/vite-plugin-uni-pages';
5
- import Layouts from '@uni-helper/vite-plugin-uni-layouts';
6
6
  import Components from '@uni-helper/vite-plugin-uni-components';
7
- import AutoImport from 'unplugin-auto-import/vite';
7
+ import Layouts from '@uni-helper/vite-plugin-uni-layouts';
8
+ import Pages from '@uni-helper/vite-plugin-uni-pages';
9
+ import defu from 'defu';
8
10
  import UnoCSS from 'unocss/vite';
11
+ import AutoImport from 'unplugin-auto-import/vite';
9
12
  import { resolvePathSync } from 'mlly';
10
- import fs from 'fs-extra';
11
13
  import { readFileSync } from 'node:fs';
12
14
  import process from 'node:process';
13
- import { resolveModule } from 'local-pkg';
14
15
  import { uniuseAutoImports } from '@uni-helper/uni-use';
16
+ import { resolveModule } from 'local-pkg';
17
+
18
+ function generateMainTs(options, vixt) {
19
+ const { buildDir, buildDirName, srcDir } = vixt.options;
20
+ const mainTsPath = path.resolve(srcDir, "main.ts");
21
+ if (!fs.existsSync(mainTsPath))
22
+ fs.outputFileSync(mainTsPath, `// Generated by Vixt
23
+ // This file transform from '${buildDirName}/main.ts'
24
+ `);
25
+ const appComponentTemplate = genarateAppComponent(vixt);
26
+ const cssTemplate = generateCss(options);
27
+ const appConfigTemplate = generateAppConfig(vixt);
28
+ const pluginsTemplate = generatePlugins(vixt);
29
+ const code = `// Generated by Vixt
30
+ // This file transform to '${srcDir}/main.ts'
31
+ // @ts-nocheck
32
+ ${appComponentTemplate}
33
+ ${cssTemplate}
34
+ ${appConfigTemplate}
35
+ ${pluginsTemplate}
36
+
37
+ import 'virtual:uno.css'
38
+ import { createSSRApp } from 'vue'
39
+ import * as Pinia from 'pinia'
40
+ import { createPersistedState } from 'pinia-plugin-persistedstate'
41
+ import { pages as routes } from 'virtual:uni-pages'
42
+
43
+ export function createApp() {
44
+ const app = createSSRApp(App)
45
+ const pinia = Pinia.createPinia()
46
+ pinia.use(createPersistedState({
47
+ storage: {
48
+ getItem: uni.getStorageSync,
49
+ setItem: uni.setStorageSync,
50
+ },
51
+ ...appConfig.piniaPersistedState,
52
+ }))
53
+ app.use(pinia)
54
+ usePlugins({ app, routes, pinia, appConfig })
55
+
56
+ return { app, Pinia }
57
+ }
58
+ `;
59
+ fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
60
+ return code;
61
+ }
62
+ const name$1 = "vixt:app";
63
+ const defaults$1 = {
64
+ rootId: "app",
65
+ rootTag: "div",
66
+ baseURL: "/",
67
+ css: [],
68
+ head: {
69
+ meta: [
70
+ { charset: "utf-8" },
71
+ { name: "viewport", content: "width=device-width, initial-scale=1" }
72
+ ]
73
+ }
74
+ };
75
+ const appUni = defineVixtModule({
76
+ meta: { name: name$1, configKey: "app" },
77
+ defaults: defaults$1,
78
+ setup(options, vixt) {
79
+ let indexHtmlCode;
80
+ let mainTsCode;
81
+ const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
82
+ return {
83
+ name: name$1,
84
+ configResolved() {
85
+ indexHtmlCode = generateIndexHtml(options, vixt);
86
+ mainTsCode = generateMainTs(options, vixt);
87
+ },
88
+ transformIndexHtml: {
89
+ order: "pre",
90
+ handler() {
91
+ return indexHtmlCode;
92
+ }
93
+ },
94
+ transform: {
95
+ order: "pre",
96
+ handler(_, id) {
97
+ if (id !== mainTsPath)
98
+ return;
99
+ return mainTsCode;
100
+ }
101
+ }
102
+ };
103
+ }
104
+ });
15
105
 
16
106
  const name = "vixt:preset-uni";
17
107
  const presetUni = defineVixtModule({
@@ -117,29 +207,7 @@ function useImports() {
117
207
  }
118
208
 
119
209
  const defaults = {
120
- modules: [presetUni],
121
- app: {
122
- transformMain(code) {
123
- code += `
124
- import 'virtual:uno.css'
125
- import { createSSRApp } from 'vue'
126
- import * as Pinia from 'pinia'
127
- import { createUnistorage } from 'pinia-plugin-unistorage'
128
- import { pages as routes } from 'virtual:uni-pages'
129
-
130
- export function createApp() {
131
- const app = createSSRApp(App)
132
- const pinia = Pinia.createPinia()
133
- pinia.use(createUnistorage(appConfig.piniaPersistedState))
134
- app.use(pinia)
135
- usePlugins({ app, routes, pinia, appConfig })
136
-
137
- return { app, Pinia }
138
- }
139
- `;
140
- return code;
141
- }
142
- },
210
+ modules: [appUni, presetUni],
143
211
  typescript: {
144
212
  tsConfig: {
145
213
  compilerOptions: {
@@ -153,4 +221,4 @@ export function createApp() {
153
221
  };
154
222
  const index = createVixtPlugin({ defaults });
155
223
 
156
- export { index as default, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
224
+ export { appUni, index as default, generateMainTs, patchNormalizeNodeModules, presetUni, uniPatch, useImports, vueusePolyfill };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/uni",
3
3
  "type": "module",
4
- "version": "0.1.17",
4
+ "version": "0.1.19",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -27,11 +27,12 @@
27
27
  "@uni-helper/vite-plugin-uni-pages": "0.2.24",
28
28
  "@vueuse/core": "^11.0.3",
29
29
  "pinia": "^2.2.2",
30
- "pinia-plugin-unistorage": "^0.1.2",
30
+ "pinia-plugin-persistedstate": "^4.0.0",
31
31
  "unocss": "0.61.6",
32
32
  "unplugin-auto-import": "^0.18.2",
33
- "vue": "^3.5.0",
34
- "@vixt/core": "0.1.17"
33
+ "vue": "^3.5.3",
34
+ "@vixt/core": "0.1.19",
35
+ "@vixt/vue": "0.1.19"
35
36
  },
36
37
  "scripts": {
37
38
  "build": "unbuild"