@vixt/uni 0.0.2 → 0.0.4

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,6 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+
4
+ declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
5
+
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+
4
+ declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
5
+
6
+ export { _default as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,138 @@
1
+ import { defineVixtModule, resolveLayersDirs, defineVitePlugin, createVixtPlugin } from '@vixt/core';
2
+ import path from 'pathe';
3
+ import defu from 'defu';
4
+ import Uni from '@dcloudio/vite-plugin-uni';
5
+ import Pages from '@uni-helper/vite-plugin-uni-pages';
6
+ import Layouts from '@uni-helper/vite-plugin-uni-layouts';
7
+ import Components from '@uni-helper/vite-plugin-uni-components';
8
+ import AutoImport from 'unplugin-auto-import/vite';
9
+ import UnoCSS from 'unocss/vite';
10
+
11
+ function resolveLayersPlugins(layers, from) {
12
+ const { plugins = [] } = resolveLayersDirs(layers);
13
+ return plugins.map((pluginPath) => {
14
+ const pluginsDir = path.relative(from, pluginPath);
15
+ return `${pluginsDir}/*.ts`;
16
+ });
17
+ }
18
+ const name$1 = "vixt:entry";
19
+ const entry = defineVixtModule({
20
+ meta: { name: name$1, configKey: "app" },
21
+ defaults: {
22
+ css: ["virtual:uno.css"]
23
+ },
24
+ setup(options, vixt) {
25
+ let config;
26
+ return {
27
+ name: "vixt:entry",
28
+ enforce: "pre",
29
+ configResolved(_config) {
30
+ config = _config;
31
+ },
32
+ transform(code, id) {
33
+ const mainPath = path.resolve(config.root, "src/main.ts");
34
+ if (id !== mainPath)
35
+ return;
36
+ const { buildDir } = vixt.options;
37
+ const layersPluginsPath = resolveLayersPlugins(vixt._layers, path.join(config.root, buildDir));
38
+ const cssTemplate = options?.css?.map((e) => `import '${e}'`).join("\n");
39
+ code += `
40
+ import * as Pinia from 'pinia'
41
+ import { createUnistorage } from 'pinia-plugin-unistorage'
42
+ import { pages } from 'virtual:uni-pages'
43
+ ${cssTemplate}
44
+ `;
45
+ code = code.replace(
46
+ /(createApp[\s\S]*?)(return\s\{\s*app)/,
47
+ `$1
48
+ const pinia = Pinia.createPinia()
49
+ pinia.use(createUnistorage())
50
+ app.use(pinia)
51
+
52
+ // install all plugins under 'plugins/'
53
+ const plugins = import.meta.glob(${JSON.stringify(layersPluginsPath)}, { import: 'default', eager: true })
54
+ // @ts-ignore
55
+ Object.values(plugins).forEach((plugin) => typeof plugin === 'function' && plugin({ app, routes: pages, pinia }) )
56
+ $2`
57
+ );
58
+ return code;
59
+ }
60
+ };
61
+ }
62
+ });
63
+
64
+ const name = "vixt:preset-uni";
65
+ const presetUni = defineVixtModule({
66
+ meta: { name },
67
+ setup(_, vixt) {
68
+ const { components, composables = [], constants = [], utils = [], stores = [] } = resolveLayersDirs(vixt._layers);
69
+ const typesDir = `${vixt.options.buildDir}/types`;
70
+ const defaultOptions = {
71
+ uni: {},
72
+ pages: { dts: `${typesDir}/uni-pages.d.ts` },
73
+ layouts: {},
74
+ components: {
75
+ dts: `${typesDir}/components.d.ts`,
76
+ dirs: components,
77
+ directoryAsNamespace: true,
78
+ collapseSamePrefixes: true,
79
+ allowOverrides: true
80
+ },
81
+ imports: {
82
+ imports: ["vue", "@vueuse/core", "uni-app", "pinia"],
83
+ dts: `${typesDir}/auto-imports.d.ts`,
84
+ dirs: [...composables, ...constants, ...stores, ...utils],
85
+ vueTemplate: true
86
+ },
87
+ unocss: {}
88
+ };
89
+ const options = defu(vixt.options, defaultOptions);
90
+ const modules = [
91
+ Pages(options.pages),
92
+ Layouts(options.layouts),
93
+ Components(options.components),
94
+ AutoImport(options.imports),
95
+ UnoCSS(options.unocss),
96
+ // @ts-expect-error
97
+ Uni.default(options.uni),
98
+ uniPatch()
99
+ ];
100
+ return modules;
101
+ }
102
+ });
103
+
104
+ function vueusePolyfill(code, id) {
105
+ if (!id.endsWith("@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js"))
106
+ return code;
107
+ code += `
108
+ export const render = () => {}
109
+ export const TransitionGroup = {}
110
+ `;
111
+ return code;
112
+ }
113
+ const uniPatch = defineVitePlugin(() => {
114
+ return {
115
+ name: "vixt:uni-patch",
116
+ transform(code, id) {
117
+ code = vueusePolyfill(code, id);
118
+ return code;
119
+ }
120
+ };
121
+ });
122
+
123
+ const defaults = {
124
+ modules: [entry, presetUni],
125
+ app: {
126
+ head: {
127
+ link: [{ rel: "icon", href: "/static/favicon.ico" }]
128
+ },
129
+ main: "src/main.ts"
130
+ },
131
+ typescript: {
132
+ references: ["types/uni-pages.d.ts", "types/components.d.ts", "types/auto-imports.d.ts", "types/vite-env.d.ts"],
133
+ tsConfig: { compilerOptions: { types: ["@dcloudio/types", "@uni-helper/vite-plugin-uni-pages/client"] } }
134
+ }
135
+ };
136
+ const index = createVixtPlugin({ defaults });
137
+
138
+ export { index as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/uni",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -31,7 +31,7 @@
31
31
  "unocss": "^0.61.0",
32
32
  "unplugin-auto-import": "^0.17.6",
33
33
  "vue": "^3.4.31",
34
- "@vixt/core": "0.0.2"
34
+ "@vixt/core": "0.0.4"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "unbuild"