@vixt/uni 0.5.17 → 0.6.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.
@@ -0,0 +1,12 @@
1
+ import "virtual:vixt:css";
2
+ import "virtual:uno.css";
3
+ import * as Pinia from "pinia";
4
+ import * as vue0 from "vue";
5
+
6
+ //#region src/client/entry.d.ts
7
+ declare function createApp(): {
8
+ app: vue0.App<Element>;
9
+ Pinia: typeof Pinia;
10
+ };
11
+ //#endregion
12
+ export { createApp as default };
@@ -0,0 +1,25 @@
1
+ import "virtual:vixt:css";
2
+ import "virtual:uno.css";
3
+ import { applyPlugins, createVixtApp } from "@vixt/core/client";
4
+ import * as Pinia from "pinia";
5
+ import appConfig from "virtual:vixt:app-config";
6
+ import plugins from "virtual:vixt:plugins";
7
+ import { createSSRApp } from "vue";
8
+ import RootComponent from "@/App.vue";
9
+
10
+ //#region src/client/entry.ts
11
+ function createApp() {
12
+ const app = createSSRApp(RootComponent);
13
+ applyPlugins(createVixtApp({
14
+ app,
15
+ appConfig
16
+ }), plugins);
17
+ return {
18
+ app,
19
+ Pinia
20
+ };
21
+ }
22
+ var entry_default = createApp;
23
+
24
+ //#endregion
25
+ export { entry_default as default };
@@ -0,0 +1,6 @@
1
+ import * as _vixt_core_client0 from "@vixt/core/client";
2
+
3
+ //#region src/client/plugins/pinia.d.ts
4
+ declare const _default: _vixt_core_client0.VixtPlugin;
5
+ //#endregion
6
+ export { _default as default };
@@ -0,0 +1,24 @@
1
+ import { defineVixtPlugin } from "@vixt/core/client";
2
+ import { createPinia } from "pinia";
3
+ import { createPersistedState } from "pinia-plugin-persistedstate";
4
+
5
+ //#region src/client/plugins/pinia.ts
6
+ var pinia_default = defineVixtPlugin({
7
+ name: "vixt:pinia",
8
+ setup(vixt) {
9
+ const { app, appConfig } = vixt;
10
+ const pinia = createPinia();
11
+ pinia.use(createPersistedState({
12
+ storage: {
13
+ getItem: uni.getStorageSync,
14
+ setItem: uni.setStorageSync
15
+ },
16
+ ...appConfig.piniaPersistedState
17
+ }));
18
+ app.use(pinia);
19
+ vixt.pinia = pinia;
20
+ }
21
+ });
22
+
23
+ //#endregion
24
+ export { pinia_default as default };
@@ -0,0 +1,6 @@
1
+ import * as _vixt_core_client0 from "@vixt/core/client";
2
+
3
+ //#region src/client/plugins/router.d.ts
4
+ declare const _default: _vixt_core_client0.VixtPlugin;
5
+ //#endregion
6
+ export { _default as default };
@@ -0,0 +1,13 @@
1
+ import { defineVixtPlugin } from "@vixt/core/client";
2
+ import { pages } from "virtual:uni-pages";
3
+
4
+ //#region src/client/plugins/router.ts
5
+ var router_default = defineVixtPlugin({
6
+ name: "vixt:router",
7
+ setup(vixt) {
8
+ vixt.routes = pages;
9
+ }
10
+ });
11
+
12
+ //#endregion
13
+ export { router_default as default };
package/dist/index.d.mts CHANGED
@@ -1,107 +1,7 @@
1
- import * as vite from 'vite';
2
- import { ResolvedConfig } from 'vite';
3
- import * as _vixt_core from '@vixt/core';
4
- import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
5
- import Pages, { PageMetaDatum } from '@uni-helper/vite-plugin-uni-pages';
6
- import { Pinia } from 'pinia';
7
- import { PluginOptions } from 'pinia-plugin-persistedstate';
8
- import { App } from 'vue';
9
- import Uni from '@dcloudio/vite-plugin-uni';
10
- import Components from '@uni-helper/vite-plugin-uni-components';
11
- import Layouts from '@uni-helper/vite-plugin-uni-layouts';
12
- import UnoCSS from 'unocss/vite';
13
- import AutoImport from 'unplugin-auto-import/vite';
14
- import { ImportsMap } from 'unplugin-auto-import/types';
1
+ import * as _vixt_core0 from "@vixt/core";
2
+ import * as vite0 from "vite";
15
3
 
16
- declare module '@vixt/core/client' {
17
- interface VixtAppConfig {
18
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
19
- piniaPersistedState?: PluginOptions
20
- }
21
-
22
- interface VixtApp {
23
- app: App
24
- routes: PageMetaDatum[]
25
- pinia: Pinia
26
- appConfig: VixtAppConfig
27
- }
28
- }
29
-
30
- declare const appUni: _vixt_core.VixtModule<AppOptions>;
31
-
32
- declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
33
-
34
- declare module '@vixt/core' {
35
- interface VixtOptions {
36
- uni?: PluginOptions$1<typeof Uni>;
37
- /** https://github.com/uni-helper/vite-plugin-uni-pages */
38
- uniPages?: PluginOptions$1<typeof Pages>;
39
- /** https://github.com/uni-helper/vite-plugin-uni-layouts */
40
- uniLayouts?: PluginOptions$1<typeof Layouts>;
41
- /** https://github.com/uni-helper/vite-plugin-uni-components */
42
- uniComponents?: PluginOptions$1<typeof Components>;
43
- /** https://github.com/antfu/unplugin-auto-import */
44
- imports?: PluginOptions$1<typeof AutoImport>;
45
- /** https://github.com/antfu/unocss */
46
- unocss?: PluginOptions$1<typeof UnoCSS>;
47
- }
48
- }
49
- declare module '@vixt/core/client' {
50
- interface VixtAppConfig {
51
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
52
- piniaPersistedState?: PluginOptions;
53
- }
54
- }
55
- declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
56
-
57
- declare module '@vixt/core' {
58
- interface VixtOptions {
59
- uniModules?: ModuleOptions;
60
- }
61
- }
62
- interface ModuleOptions {
63
- include?: string[];
64
- exclude?: string[];
65
- }
66
- declare const uniModules: _vixt_core.VixtModule<_vixt_core.ModuleOptions>;
67
-
68
- /** 增加小程序中vueuse的运行所需 */
69
- declare function transformMpRuntime(code: string, id: string): string;
70
- /**
71
- * 修复h5报错`Cannot assign to read only property '_' of object '#<Object>'`
72
- * @see https://ask.dcloud.net.cn/question/194973
73
- */
74
- declare function transformH5Runtime(code: string, id: string): string;
75
- /** 修复app运行白屏,原因是pinia调用了@vue/devtools-kit的setupDevToolsPlugin */
76
- declare function transformVueDevtools(code: string, id: string): string;
77
- /** 移除路径中的'../' */
78
- declare function patchNormalizeNodeModules(): void;
79
- /**
80
- * 兼容 unocss^66.1.0 小程序平台的css文件后缀名
81
- * @see https://github.com/dcloudio/uni-app/pull/5605/files
82
- */
83
- declare function patchAdjustCssExtname(config: ResolvedConfig): void;
84
- /**
85
- * fix unocss^66.1.0 hot reload fail `[unocss:global:build:scan] Could not load xxx/src/__uno.css`
86
- * @see https://github.com/unocss/unocss/issues/4616
87
- * @see https://github.com/unocss/unocss/pull/4737
88
- */
89
- declare function patchUnocssGlobalBuildScan(config: ResolvedConfig): void;
90
- /**
91
- * fix `@uni-helper/vite-plugin-uni-components` load slowly
92
- * @see https://github.com/uni-helper/vite-plugin-uni-components/blob/main/packages/core/src/index.ts#L27
93
- */
94
- declare function patchUniComponents(config: ResolvedConfig): void;
95
- /**
96
- * fix `@uni-helper/vite-plugin-uni-pages` client types
97
- * @see https://github.com/uni-helper/vite-plugin-uni-pages/blob/main/packages/core/client.d.ts#L4
98
- */
99
- declare function patchUniPagesTypes(): void;
100
- declare const uniPatch: (options?: any) => vite.PluginOption;
101
-
102
- declare function uniVueUseResolver(): ImportsMap;
103
-
104
- declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
105
-
106
- export { appUni, _default as default, generateMainTs, patchAdjustCssExtname, patchNormalizeNodeModules, patchUniComponents, patchUniPagesTypes, patchUnocssGlobalBuildScan, presetUni, transformH5Runtime, transformMpRuntime, transformVueDevtools, uniModules, uniPatch, uniVueUseResolver };
107
- export type { ModuleOptions };
4
+ //#region src/index.d.ts
5
+ declare const _default: (options?: _vixt_core0.VixtOptions | undefined) => vite0.PluginOption;
6
+ //#endregion
7
+ export { _default as default };
package/dist/index.mjs CHANGED
@@ -1,344 +1,292 @@
1
- import { generateClient, generateCss, generateAppConfig, generatePlugins, defineVixtModule, generateIndexHtml, defineVitePlugin, resolveLayersDirs, isSamePath, createVixtPlugin } from '@vixt/core';
2
- import path from 'pathe';
3
- import { genarateAppComponent } from '@vixt/vue';
4
- import fs from 'fs-extra';
5
- import Uni from '@dcloudio/vite-plugin-uni';
6
- import Components from '@uni-helper/vite-plugin-uni-components';
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';
10
- import UnoCSS from 'unocss/vite';
11
- import AutoImport from 'unplugin-auto-import/vite';
12
- import { resolvePathSync } from 'mlly';
13
- import { normalizePath } from 'vite';
14
- import { readFileSync } from 'node:fs';
15
- import process from 'node:process';
16
- import { uniuseAutoImports } from '@uni-helper/uni-use';
17
- import { resolveModule } from 'local-pkg';
18
-
19
- function generateMainTs(options, vixt) {
20
- const { buildDir, srcDir } = vixt.options;
21
- const mainTsPath = path.resolve(srcDir, "main.ts");
22
- if (!fs.existsSync(mainTsPath))
23
- fs.outputFileSync(mainTsPath, `// Generated by Vixt
24
- // This file transform from '${path.basename(buildDir)}/main.ts'
25
- `);
26
- generateClient(vixt);
27
- const appComponentTemplate = genarateAppComponent(vixt);
28
- const cssTemplate = generateCss(options);
29
- const appConfigTemplate = generateAppConfig(vixt);
30
- const pluginsTemplate = generatePlugins(vixt);
31
- const code = `// Generated by Vixt
32
- // This file transform to '${srcDir}/main.ts'
33
- // @ts-nocheck
34
- ${appComponentTemplate}
35
- ${cssTemplate}
36
- ${appConfigTemplate}
37
- ${pluginsTemplate}
38
-
39
- import 'virtual:uno.css'
40
- import { createSSRApp } from 'vue'
41
- import * as Pinia from 'pinia'
42
- import { createPersistedState } from 'pinia-plugin-persistedstate'
43
- import { pages as routes } from 'virtual:uni-pages'
44
-
45
- export function createApp() {
46
- const app = createSSRApp(App)
47
- const pinia = Pinia.createPinia()
48
- pinia.use(createPersistedState({
49
- storage: {
50
- getItem: uni.getStorageSync,
51
- setItem: uni.setStorageSync,
52
- },
53
- ...appConfig.piniaPersistedState,
54
- }))
55
- app.use(pinia)
56
- usePlugins({ app, routes, pinia, appConfig })
57
-
58
- return { app, Pinia }
59
- }
60
- `;
61
- fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
62
- return code;
63
- }
64
-
65
- const name$2 = "vixt:app-uni";
66
- const defaults$1 = {
67
- rootId: "app",
68
- rootTag: "div",
69
- baseURL: "/",
70
- entryFile: "main.ts",
71
- css: [],
72
- head: {
73
- meta: [
74
- { charset: "utf-8" },
75
- { name: "viewport", content: "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" }
76
- ]
77
- }
78
- };
79
- const appUni = defineVixtModule({
80
- meta: { name: name$2, configKey: "app" },
81
- defaults: defaults$1,
82
- setup(options, vixt) {
83
- let indexHtmlCode;
84
- let mainTsCode;
85
- const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
86
- return {
87
- name: name$2,
88
- configResolved() {
89
- indexHtmlCode = generateIndexHtml(options, vixt);
90
- mainTsCode = generateMainTs(options, vixt);
91
- },
92
- transformIndexHtml: {
93
- order: "pre",
94
- handler() {
95
- return indexHtmlCode;
96
- }
97
- },
98
- transform: {
99
- order: "pre",
100
- handler(_, id) {
101
- if (id !== mainTsPath)
102
- return;
103
- return mainTsCode;
104
- }
105
- }
106
- };
107
- }
108
- });
1
+ import { VixtClientAutoImports, createVixtPlugin, defineVitePlugin, defineVixtModule, isSamePath, resolveLayersDirs } from "@vixt/core";
2
+ import fs from "fs-extra";
3
+ import { resolvePathSync } from "mlly";
4
+ import Uni from "@dcloudio/vite-plugin-uni";
5
+ import Components from "@uni-helper/vite-plugin-uni-components";
6
+ import Layouts from "@uni-helper/vite-plugin-uni-layouts";
7
+ import Pages from "@uni-helper/vite-plugin-uni-pages";
8
+ import defu from "defu";
9
+ import UnoCSS from "unocss/vite";
10
+ import AutoImport from "unplugin-auto-import/vite";
11
+ import path from "pathe";
12
+ import { normalizePath } from "vite";
13
+ import { readFileSync } from "node:fs";
14
+ import process from "node:process";
15
+ import { uniuseAutoImports } from "@uni-helper/uni-use";
16
+ import { resolveModule } from "local-pkg";
109
17
 
18
+ //#region src/modules/uni-patch.ts
19
+ /** 增加小程序中vueuse的运行所需 */
110
20
  function transformMpRuntime(code, id) {
111
- if (!id.endsWith("@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js"))
112
- return code;
113
- code += `
21
+ if (!id.endsWith("@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js")) return code;
22
+ code += `
114
23
  export const render = () => {}
115
24
  export const TransitionGroup = {}
116
25
  `;
117
- return code;
26
+ return code;
118
27
  }
28
+ /**
29
+ * 修复h5报错`Cannot assign to read only property '_' of object '#<Object>'`
30
+ * @see https://ask.dcloud.net.cn/question/194973
31
+ */
119
32
  function transformH5Runtime(code, id) {
120
- if (!id.endsWith("@dcloudio/uni-h5-vue/dist/vue.runtime.esm.js"))
121
- return code;
122
- code = code.replace(`def(children, "_", type);`, `def(children, "_", type, true);`);
123
- return code;
33
+ if (!id.endsWith("@dcloudio/uni-h5-vue/dist/vue.runtime.esm.js")) return code;
34
+ code = code.replace(`def(children, "_", type);`, `def(children, "_", type, true);`);
35
+ return code;
124
36
  }
125
- function transformVueDevtools(code, id) {
126
- if (!id.endsWith("@vue/devtools-kit/dist/index.js"))
127
- return code;
128
- code = code.replace(`function setupDevToolsPlugin(pluginDescriptor, setupFn) {
129
- return hook.setupDevToolsPlugin(pluginDescriptor, setupFn);
130
- }`, `function setupDevToolsPlugin(pluginDescriptor, setupFn) {}`);
131
- return code;
37
+ /** 修复app运行白屏,原因是pinia调用了@vue/devtools-kit的setupDevToolsPlugin */
38
+ function transformPinia(code, id) {
39
+ if (!id.endsWith("pinia/dist/pinia.mjs")) return code;
40
+ code = code.replace(`import { setupDevtoolsPlugin } from '@vue/devtools-api';`, `function setupDevtoolsPlugin() {};`);
41
+ return code;
132
42
  }
43
+ /** 移除路径中的'../' */
133
44
  function patchNormalizeNodeModules() {
134
- const matched = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules');`;
135
- const replaced = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules').replace(/\\.\\.\\//g, '');`;
136
- const codePath = resolvePathSync("@dcloudio/uni-cli-shared/dist/utils.js");
137
- let code = fs.readFileSync(codePath, "utf8");
138
- if (code.includes(matched)) {
139
- code = code.replace(matched, replaced);
140
- fs.writeFileSync(codePath, code);
141
- }
45
+ const matched = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules');`;
46
+ const replaced = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules').replace(/\\.\\.\\//g, '');`;
47
+ const codePath = resolvePathSync("@dcloudio/uni-cli-shared/dist/utils.js");
48
+ let code = fs.readFileSync(codePath, "utf8");
49
+ if (code.includes(matched)) {
50
+ code = code.replace(matched, replaced);
51
+ fs.writeFileSync(codePath, code);
52
+ }
142
53
  }
54
+ /**
55
+ * 兼容 unocss^66.1.0 小程序平台的css文件后缀名
56
+ * @see https://github.com/dcloudio/uni-app/pull/5605/files
57
+ */
143
58
  function patchAdjustCssExtname(config) {
144
- const plugin = config.plugins.find((p) => p.name === "uni:adjust-css-extname");
145
- if (plugin && typeof plugin.generateBundle === "function") {
146
- const handler = plugin.generateBundle;
147
- plugin.generateBundle = { order: "post", handler };
148
- }
59
+ const plugin = config.plugins.find((p) => p.name === "uni:adjust-css-extname");
60
+ if (plugin && typeof plugin.generateBundle === "function") plugin.generateBundle = {
61
+ order: "post",
62
+ handler: plugin.generateBundle
63
+ };
149
64
  }
65
+ /**
66
+ * fix unocss^66.1.0 hot reload fail `[unocss:global:build:scan] Could not load xxx/src/__uno.css`
67
+ * @see https://github.com/unocss/unocss/issues/4616
68
+ * @see https://github.com/unocss/unocss/pull/4737
69
+ */
150
70
  function patchUnocssGlobalBuildScan(config) {
151
- const plugin = config.plugins.find((p) => p.name === "unocss:global:build:scan");
152
- if (plugin)
153
- plugin.shouldTransformCachedModule = ({ id }) => id.endsWith("main.ts");
71
+ const plugin = config.plugins.find((p) => p.name === "unocss:global:build:scan");
72
+ if (plugin) plugin.shouldTransformCachedModule = ({ id }) => id.endsWith("main.ts");
154
73
  }
74
+ /**
75
+ * fix `@uni-helper/vite-plugin-uni-components` load slowly
76
+ * @see https://github.com/uni-helper/vite-plugin-uni-components/blob/main/packages/core/src/index.ts#L27
77
+ */
155
78
  function patchUniComponents(config) {
156
- if (JSON.stringify(config.build.watch) === "{}")
157
- config.build.watch = null;
79
+ if (JSON.stringify(config.build.watch) === "{}") config.build.watch = null;
158
80
  }
81
+ /**
82
+ * fix `@uni-helper/vite-plugin-uni-pages` client types
83
+ * @see https://github.com/uni-helper/vite-plugin-uni-pages/blob/main/packages/core/client.d.ts#L4
84
+ */
159
85
  function patchUniPagesTypes() {
160
- const matched = ` import type { SubPackage } from './src/config/types/index'
161
- import type { PageMetaDatum } from './src/types'`;
162
- const replaced = ` import type { PageMetaDatum, SubPackage } from '@uni-helper/vite-plugin-uni-pages'`;
163
- const codePath = path.resolve(resolvePathSync("@uni-helper/vite-plugin-uni-pages"), "../../client.d.ts");
164
- let code = codePath && fs.readFileSync(codePath, "utf-8");
165
- if (code.includes(matched)) {
166
- code = code.replace(matched, replaced);
167
- fs.outputFileSync(codePath, code);
168
- }
86
+ const matched = ` import type { SubPackage } from './src/config/types/index'\n import type { PageMetaDatum } from './src/types'`;
87
+ const replaced = ` import type { PageMetaDatum, SubPackage } from '@uni-helper/vite-plugin-uni-pages'`;
88
+ const codePath = path.resolve(resolvePathSync("@uni-helper/vite-plugin-uni-pages"), "../../client.d.ts");
89
+ let code = codePath && fs.readFileSync(codePath, "utf-8");
90
+ if (code.includes(matched)) {
91
+ code = code.replace(matched, replaced);
92
+ fs.outputFileSync(codePath, code);
93
+ }
169
94
  }
170
95
  const uniPatch = defineVitePlugin(() => {
171
- patchNormalizeNodeModules();
172
- patchUniPagesTypes();
173
- return [
174
- {
175
- name: "vixt:uni-patch-runtime",
176
- transform(code, id) {
177
- id = normalizePath(id);
178
- code = transformMpRuntime(code, id);
179
- code = transformH5Runtime(code, id);
180
- code = transformVueDevtools(code, id);
181
- return code;
182
- }
183
- },
184
- {
185
- name: "vixt:uni-patch-uni-components",
186
- configResolved(config) {
187
- patchUniComponents(config);
188
- }
189
- },
190
- {
191
- name: "vixt:uni-patch-unocss-global-build-scan",
192
- apply: "build",
193
- enforce: "pre",
194
- configResolved(config) {
195
- patchUnocssGlobalBuildScan(config);
196
- }
197
- },
198
- {
199
- name: "vixt:uni-patch-adjust-css-extname",
200
- enforce: "post",
201
- configResolved(config) {
202
- patchAdjustCssExtname(config);
203
- }
204
- }
205
- ];
96
+ patchNormalizeNodeModules();
97
+ patchUniPagesTypes();
98
+ return [
99
+ {
100
+ name: "vixt:uni-patch-runtime",
101
+ transform(code, id) {
102
+ id = normalizePath(id);
103
+ code = transformMpRuntime(code, id);
104
+ code = transformH5Runtime(code, id);
105
+ code = transformPinia(code, id);
106
+ return code;
107
+ }
108
+ },
109
+ {
110
+ name: "vixt:uni-patch-uni-components",
111
+ configResolved(config) {
112
+ patchUniComponents(config);
113
+ }
114
+ },
115
+ {
116
+ name: "vixt:uni-patch-unocss-global-build-scan",
117
+ apply: "build",
118
+ enforce: "pre",
119
+ configResolved(config) {
120
+ patchUnocssGlobalBuildScan(config);
121
+ }
122
+ },
123
+ {
124
+ name: "vixt:uni-patch-adjust-css-extname",
125
+ enforce: "post",
126
+ configResolved(config) {
127
+ patchAdjustCssExtname(config);
128
+ }
129
+ }
130
+ ];
206
131
  });
207
132
 
133
+ //#endregion
134
+ //#region src/modules/uni-use.ts
208
135
  let _cache;
209
136
  function uniVueUseResolver() {
210
- const excluded = [
211
- "toRefs",
212
- "utils",
213
- "toRef",
214
- "toValue",
215
- "tryOnScopeDispose",
216
- "useNetwork",
217
- "useOnline",
218
- "usePreferredDark",
219
- "useStorage",
220
- "useStorageAsync"
221
- ];
222
- if (!_cache) {
223
- let indexesJson;
224
- try {
225
- const corePath = resolveModule("@vueuse/core") || process.cwd();
226
- const path = resolveModule("@vueuse/core/indexes.json") || resolveModule("@vueuse/metadata/index.json") || resolveModule("@vueuse/metadata/index.json", { paths: [corePath] });
227
- indexesJson = JSON.parse(readFileSync(path, "utf-8"));
228
- } catch (error) {
229
- console.error(error);
230
- throw new Error("[auto-import] failed to load @vueuse/core, have you installed it?");
231
- }
232
- if (indexesJson) {
233
- _cache = {
234
- "@vueuse/core": indexesJson.functions.filter((i) => ["core", "shared"].includes(i.package)).flatMap((i) => [i.name, ...i.alias || []]).filter((i) => i && i.length >= 4 && !excluded.includes(i)),
235
- ...uniuseAutoImports()
236
- };
237
- }
238
- }
239
- return _cache || {};
137
+ const excluded = [
138
+ "toRefs",
139
+ "utils",
140
+ "toRef",
141
+ "toValue",
142
+ "tryOnScopeDispose",
143
+ "useNetwork",
144
+ "useOnline",
145
+ "usePreferredDark",
146
+ "useStorage",
147
+ "useStorageAsync"
148
+ ];
149
+ if (!_cache) {
150
+ let indexesJson;
151
+ try {
152
+ const corePath = resolveModule("@vueuse/core") || process.cwd();
153
+ const path$1 = resolveModule("@vueuse/core/indexes.json") || resolveModule("@vueuse/metadata/index.json") || resolveModule("@vueuse/metadata/index.json", { paths: [corePath] });
154
+ indexesJson = JSON.parse(readFileSync(path$1, "utf-8"));
155
+ } catch (error) {
156
+ console.error(error);
157
+ throw new Error("[auto-import] failed to load @vueuse/core, have you installed it?");
158
+ }
159
+ if (indexesJson) _cache = {
160
+ "@vueuse/core": indexesJson.functions.filter((i) => ["core", "shared"].includes(i.package)).flatMap((i) => [i.name, ...i.alias || []]).filter((i) => i && i.length >= 4 && !excluded.includes(i)),
161
+ ...uniuseAutoImports()
162
+ };
163
+ }
164
+ return _cache || {};
240
165
  }
241
166
 
167
+ //#endregion
168
+ //#region src/modules/preset-uni.ts
242
169
  const name$1 = "vixt:preset-uni";
243
- const presetUni = defineVixtModule({
244
- meta: { name: name$1 },
245
- setup(_, vixt) {
246
- const { components = [], composables = [], constants = [], utils = [], stores = [] } = resolveLayersDirs([...vixt._layers].reverse());
247
- const { buildTypesDir, buildImportsDir } = vixt.options;
248
- const defaultOptions = {
249
- uni: {},
250
- uniPages: { dts: `${buildTypesDir}/uni-pages.d.ts` },
251
- uniLayouts: {},
252
- uniComponents: {
253
- dts: `${buildTypesDir}/components.d.ts`,
254
- dirs: [...components].reverse(),
255
- directoryAsNamespace: true,
256
- collapseSamePrefixes: true
257
- },
258
- imports: {
259
- imports: ["vue", "uni-app", "pinia", uniVueUseResolver()],
260
- dts: `${buildTypesDir}/auto-imports.d.ts`,
261
- dirs: [composables, constants, stores, utils, buildImportsDir].flat(),
262
- vueTemplate: true
263
- },
264
- unocss: {}
265
- };
266
- const options = vixt.options = defu(vixt.options, defaultOptions);
267
- const modules = [
268
- Pages(options.uniPages),
269
- Layouts(options.uniLayouts),
270
- Components(options.uniComponents),
271
- AutoImport(options.imports),
272
- UnoCSS(options.unocss),
273
- uniPatch(),
274
- // @ts-expect-error
275
- Uni.default(options.uni)
276
- ];
277
- return modules;
278
- }
170
+ var preset_uni_default = defineVixtModule({
171
+ meta: { name: name$1 },
172
+ setup(_, vixt) {
173
+ const { components = [], composables = [], constants = [], utils = [], stores = [] } = resolveLayersDirs([...vixt._layers].reverse());
174
+ const { buildTypesDir } = vixt.options;
175
+ const defaultOptions = {
176
+ uni: {},
177
+ uniPages: { dts: `${buildTypesDir}/uni-pages.d.ts` },
178
+ uniLayouts: {},
179
+ uniComponents: {
180
+ dts: `${buildTypesDir}/components.d.ts`,
181
+ dirs: [...components].reverse(),
182
+ directoryAsNamespace: true,
183
+ collapseSamePrefixes: true
184
+ },
185
+ imports: {
186
+ imports: [
187
+ "vue",
188
+ "uni-app",
189
+ "pinia",
190
+ uniVueUseResolver(),
191
+ VixtClientAutoImports
192
+ ],
193
+ dts: `${buildTypesDir}/auto-imports.d.ts`,
194
+ dirs: [
195
+ composables,
196
+ constants,
197
+ stores,
198
+ utils
199
+ ].flat(),
200
+ vueTemplate: true
201
+ },
202
+ unocss: {}
203
+ };
204
+ const options = vixt.options = defu(vixt.options, defaultOptions);
205
+ return [
206
+ Pages(options.uniPages),
207
+ Layouts(options.uniLayouts),
208
+ Components(options.uniComponents),
209
+ AutoImport(options.imports),
210
+ UnoCSS(options.unocss),
211
+ uniPatch(),
212
+ (Uni?.default ?? Uni)(options.uni)
213
+ ];
214
+ }
279
215
  });
280
216
 
217
+ //#endregion
218
+ //#region src/modules/uni-modules.ts
281
219
  function copyUniModules(options, vixt) {
282
- const { srcDir } = vixt.options;
283
- const { include, exclude } = options ?? {};
284
- const { uni_modules = [] } = resolveLayersDirs(vixt._layers);
285
- const srcUniModulesPath = path.join(srcDir, "uni_modules");
286
- uni_modules.forEach((uniModulesPath) => {
287
- fs.readdirSync(uniModulesPath).filter((dir) => {
288
- if (include?.length)
289
- return include.includes(dir);
290
- if (exclude?.length)
291
- return !exclude.includes(dir);
292
- return true;
293
- }).forEach((dir) => {
294
- const srcPath = path.join(uniModulesPath, dir);
295
- const destPath = path.join(srcUniModulesPath, dir);
296
- if (srcPath !== destPath) {
297
- try {
298
- fs.emptyDirSync(destPath);
299
- fs.copySync(srcPath, destPath);
300
- fs.writeFileSync(path.join(destPath, ".gitignore"), "*", "utf-8");
301
- } catch (e) {
302
- console.error(`Error copying ${srcPath} to ${destPath}:
303
- `, e);
304
- }
305
- }
306
- });
307
- });
220
+ const { srcDir } = vixt.options;
221
+ const { include, exclude } = options ?? {};
222
+ const { uni_modules = [] } = resolveLayersDirs(vixt._layers);
223
+ const srcUniModulesPath = path.join(srcDir, "uni_modules");
224
+ uni_modules.forEach((uniModulesPath) => {
225
+ fs.readdirSync(uniModulesPath).filter((dir) => {
226
+ if (include?.length) return include.includes(dir);
227
+ if (exclude?.length) return !exclude.includes(dir);
228
+ return true;
229
+ }).forEach((dir) => {
230
+ const srcPath = path.join(uniModulesPath, dir);
231
+ const destPath = path.join(srcUniModulesPath, dir);
232
+ if (srcPath !== destPath) try {
233
+ fs.emptyDirSync(destPath);
234
+ fs.copySync(srcPath, destPath);
235
+ fs.writeFileSync(path.join(destPath, ".gitignore"), "*", "utf-8");
236
+ } catch (e) {
237
+ console.error(`Error copying ${srcPath} to ${destPath}:\n`, e);
238
+ }
239
+ });
240
+ });
308
241
  }
309
242
  const name = "vixt:uni-modules";
310
- const uniModules = defineVixtModule({
311
- meta: { name, configKey: "uniModules" },
312
- setup(options, vixt) {
313
- copyUniModules(options, vixt);
314
- return {
315
- name,
316
- configureServer(server) {
317
- const { uni_modules = [] } = resolveLayersDirs(vixt._layers.filter((e) => !isSamePath(e.cwd, vixt.options.rootDir)));
318
- server.watcher.add(uni_modules);
319
- server.watcher.on("all", (_, file) => {
320
- const match = uni_modules.some((e) => path.normalize(file).match(e));
321
- if (match)
322
- copyUniModules(options, vixt);
323
- });
324
- }
325
- };
326
- }
243
+ var uni_modules_default = defineVixtModule({
244
+ meta: {
245
+ name,
246
+ configKey: "uniModules"
247
+ },
248
+ setup(options, vixt) {
249
+ copyUniModules(options, vixt);
250
+ return {
251
+ name,
252
+ configureServer(server) {
253
+ const { uni_modules = [] } = resolveLayersDirs(vixt._layers.filter((e) => !isSamePath(e.cwd, vixt.options.rootDir)));
254
+ server.watcher.add(uni_modules);
255
+ server.watcher.on("all", (_, file) => {
256
+ if (uni_modules.some((e) => path.normalize(file).match(e))) copyUniModules(options, vixt);
257
+ });
258
+ }
259
+ };
260
+ }
327
261
  });
328
262
 
329
- const defaults = {
330
- modules: [uniModules, appUni, presetUni],
331
- typescript: {
332
- tsConfig: {
333
- compilerOptions: {
334
- types: ["@dcloudio/types", "@uni-helper/uni-app-types"]
335
- },
336
- vueCompilerOptions: {
337
- plugins: ["@uni-helper/uni-app-types/volar-plugin"]
338
- }
339
- }
340
- }
341
- };
342
- const index = createVixtPlugin({ defaults });
263
+ //#endregion
264
+ //#region src/index.ts
265
+ var src_default = createVixtPlugin({ defaults: {
266
+ modules: [preset_uni_default, uni_modules_default],
267
+ plugins: ["@vixt/uni/client/plugins/pinia", "@vixt/uni/client/plugins/router"],
268
+ app: {
269
+ entryFile: "main.ts",
270
+ entryCode: fs.readFileSync(resolvePathSync("@vixt/uni/client/entry"), "utf-8"),
271
+ head: { meta: [{ charset: "utf-8" }, {
272
+ name: "viewport",
273
+ content: "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
274
+ }] }
275
+ },
276
+ typescript: { tsConfig: {
277
+ compilerOptions: { types: [
278
+ "@vixt/uni/types",
279
+ "@dcloudio/types",
280
+ "@uni-helper/uni-app-types"
281
+ ] },
282
+ vueCompilerOptions: { plugins: ["@uni-helper/uni-app-types/volar-plugin"] }
283
+ } },
284
+ vite: { optimizeDeps: { exclude: [
285
+ "@vixt/uni/client/entry",
286
+ "@vixt/uni/client/plugins/pinia",
287
+ "@vixt/uni/client/plugins/router"
288
+ ] } }
289
+ } });
343
290
 
344
- export { appUni, index as default, generateMainTs, patchAdjustCssExtname, patchNormalizeNodeModules, patchUniComponents, patchUniPagesTypes, patchUnocssGlobalBuildScan, presetUni, transformH5Runtime, transformMpRuntime, transformVueDevtools, uniModules, uniPatch, uniVueUseResolver };
291
+ //#endregion
292
+ export { src_default as default };
@@ -0,0 +1,18 @@
1
+ import type { PageMetaDatum } from '@uni-helper/vite-plugin-uni-pages'
2
+ import type { Pinia } from 'pinia'
3
+ import type { PluginOptions as PersistedStateOptions } from 'pinia-plugin-persistedstate'
4
+ import type { App } from 'vue'
5
+
6
+ declare module '@vixt/core/client' {
7
+ interface VixtAppConfig {
8
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
9
+ piniaPersistedState?: PersistedStateOptions
10
+ }
11
+
12
+ interface VixtApp {
13
+ app: App
14
+ routes: PageMetaDatum[]
15
+ pinia: Pinia
16
+ appConfig: VixtAppConfig
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+ import './client.d'
2
+ import './node.d'
@@ -0,0 +1,23 @@
1
+ import type Uni from '@dcloudio/vite-plugin-uni'
2
+ import type Components from '@uni-helper/vite-plugin-uni-components'
3
+ import type Layouts from '@uni-helper/vite-plugin-uni-layouts'
4
+ import type Pages from '@uni-helper/vite-plugin-uni-pages'
5
+ import type { ExtractPluginOptions } from '@vixt/core'
6
+ import type UnoCSS from 'unocss/vite'
7
+ import type AutoImport from 'unplugin-auto-import/vite'
8
+
9
+ declare module '@vixt/core' {
10
+ interface VixtOptions {
11
+ uni?: ExtractPluginOptions<typeof Uni>
12
+ /** https://github.com/uni-helper/vite-plugin-uni-pages */
13
+ uniPages?: ExtractPluginOptions<typeof Pages>
14
+ /** https://github.com/uni-helper/vite-plugin-uni-layouts */
15
+ uniLayouts?: ExtractPluginOptions<typeof Layouts>
16
+ /** https://github.com/uni-helper/vite-plugin-uni-components */
17
+ uniComponents?: ExtractPluginOptions<typeof Components>
18
+ /** https://github.com/antfu/unplugin-auto-import */
19
+ imports?: ExtractPluginOptions<typeof AutoImport>
20
+ /** https://github.com/antfu/unocss */
21
+ unocss?: ExtractPluginOptions<typeof UnoCSS>
22
+ }
23
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/uni",
3
3
  "type": "module",
4
- "version": "0.5.17",
4
+ "version": "0.6.1",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://soullyoko.github.io/vixt/",
@@ -14,13 +14,13 @@
14
14
  "uni-app"
15
15
  ],
16
16
  "exports": {
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.mjs"
20
- }
17
+ ".": "./dist/index.mjs",
18
+ "./client/*": "./dist/client/*.js",
19
+ "./types": "./dist/types/index.d.ts",
20
+ "./package.json": "./package.json"
21
21
  },
22
- "main": "dist/index.mjs",
23
- "types": "dist/index.d.ts",
22
+ "main": "./dist/index.mjs",
23
+ "types": "./dist/types/index.d.ts",
24
24
  "files": [
25
25
  "dist"
26
26
  ],
@@ -33,11 +33,7 @@
33
33
  "@uni-helper/vite-plugin-uni-layouts": "^0.1.11",
34
34
  "@uni-helper/vite-plugin-uni-pages": "^0.3.22",
35
35
  "unocss-applet": "^0.12.2",
36
- "@vixt/vue": "0.5.17",
37
- "@vixt/core": "0.5.17"
38
- },
39
- "scripts": {
40
- "build": "unbuild",
41
- "dev": "unbuild --stub"
36
+ "@vixt/core": "0.6.1",
37
+ "@vixt/vue": "0.6.1"
42
38
  }
43
39
  }
package/dist/index.d.ts DELETED
@@ -1,107 +0,0 @@
1
- import * as vite from 'vite';
2
- import { ResolvedConfig } from 'vite';
3
- import * as _vixt_core from '@vixt/core';
4
- import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
5
- import Pages, { PageMetaDatum } from '@uni-helper/vite-plugin-uni-pages';
6
- import { Pinia } from 'pinia';
7
- import { PluginOptions } from 'pinia-plugin-persistedstate';
8
- import { App } from 'vue';
9
- import Uni from '@dcloudio/vite-plugin-uni';
10
- import Components from '@uni-helper/vite-plugin-uni-components';
11
- import Layouts from '@uni-helper/vite-plugin-uni-layouts';
12
- import UnoCSS from 'unocss/vite';
13
- import AutoImport from 'unplugin-auto-import/vite';
14
- import { ImportsMap } from 'unplugin-auto-import/types';
15
-
16
- declare module '@vixt/core/client' {
17
- interface VixtAppConfig {
18
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
19
- piniaPersistedState?: PluginOptions
20
- }
21
-
22
- interface VixtApp {
23
- app: App
24
- routes: PageMetaDatum[]
25
- pinia: Pinia
26
- appConfig: VixtAppConfig
27
- }
28
- }
29
-
30
- declare const appUni: _vixt_core.VixtModule<AppOptions>;
31
-
32
- declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
33
-
34
- declare module '@vixt/core' {
35
- interface VixtOptions {
36
- uni?: PluginOptions$1<typeof Uni>;
37
- /** https://github.com/uni-helper/vite-plugin-uni-pages */
38
- uniPages?: PluginOptions$1<typeof Pages>;
39
- /** https://github.com/uni-helper/vite-plugin-uni-layouts */
40
- uniLayouts?: PluginOptions$1<typeof Layouts>;
41
- /** https://github.com/uni-helper/vite-plugin-uni-components */
42
- uniComponents?: PluginOptions$1<typeof Components>;
43
- /** https://github.com/antfu/unplugin-auto-import */
44
- imports?: PluginOptions$1<typeof AutoImport>;
45
- /** https://github.com/antfu/unocss */
46
- unocss?: PluginOptions$1<typeof UnoCSS>;
47
- }
48
- }
49
- declare module '@vixt/core/client' {
50
- interface VixtAppConfig {
51
- /** https://github.com/prazdevs/pinia-plugin-persistedstate */
52
- piniaPersistedState?: PluginOptions;
53
- }
54
- }
55
- declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
56
-
57
- declare module '@vixt/core' {
58
- interface VixtOptions {
59
- uniModules?: ModuleOptions;
60
- }
61
- }
62
- interface ModuleOptions {
63
- include?: string[];
64
- exclude?: string[];
65
- }
66
- declare const uniModules: _vixt_core.VixtModule<_vixt_core.ModuleOptions>;
67
-
68
- /** 增加小程序中vueuse的运行所需 */
69
- declare function transformMpRuntime(code: string, id: string): string;
70
- /**
71
- * 修复h5报错`Cannot assign to read only property '_' of object '#<Object>'`
72
- * @see https://ask.dcloud.net.cn/question/194973
73
- */
74
- declare function transformH5Runtime(code: string, id: string): string;
75
- /** 修复app运行白屏,原因是pinia调用了@vue/devtools-kit的setupDevToolsPlugin */
76
- declare function transformVueDevtools(code: string, id: string): string;
77
- /** 移除路径中的'../' */
78
- declare function patchNormalizeNodeModules(): void;
79
- /**
80
- * 兼容 unocss^66.1.0 小程序平台的css文件后缀名
81
- * @see https://github.com/dcloudio/uni-app/pull/5605/files
82
- */
83
- declare function patchAdjustCssExtname(config: ResolvedConfig): void;
84
- /**
85
- * fix unocss^66.1.0 hot reload fail `[unocss:global:build:scan] Could not load xxx/src/__uno.css`
86
- * @see https://github.com/unocss/unocss/issues/4616
87
- * @see https://github.com/unocss/unocss/pull/4737
88
- */
89
- declare function patchUnocssGlobalBuildScan(config: ResolvedConfig): void;
90
- /**
91
- * fix `@uni-helper/vite-plugin-uni-components` load slowly
92
- * @see https://github.com/uni-helper/vite-plugin-uni-components/blob/main/packages/core/src/index.ts#L27
93
- */
94
- declare function patchUniComponents(config: ResolvedConfig): void;
95
- /**
96
- * fix `@uni-helper/vite-plugin-uni-pages` client types
97
- * @see https://github.com/uni-helper/vite-plugin-uni-pages/blob/main/packages/core/client.d.ts#L4
98
- */
99
- declare function patchUniPagesTypes(): void;
100
- declare const uniPatch: (options?: any) => vite.PluginOption;
101
-
102
- declare function uniVueUseResolver(): ImportsMap;
103
-
104
- declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
105
-
106
- export { appUni, _default as default, generateMainTs, patchAdjustCssExtname, patchNormalizeNodeModules, patchUniComponents, patchUniPagesTypes, patchUnocssGlobalBuildScan, presetUni, transformH5Runtime, transformMpRuntime, transformVueDevtools, uniModules, uniPatch, uniVueUseResolver };
107
- export type { ModuleOptions };