@vixt/uni 0.0.5 → 0.0.6

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.
Files changed (2) hide show
  1. package/dist/index.mjs +37 -28
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineVixtModule, resolveLayersDirs, defineVitePlugin, createVixtPlugin } from '@vixt/core';
2
2
  import path from 'pathe';
3
+ import fs from 'fs-extra';
3
4
  import defu from 'defu';
4
5
  import Uni from '@dcloudio/vite-plugin-uni';
5
6
  import Pages from '@uni-helper/vite-plugin-uni-pages';
@@ -15,6 +16,36 @@ function resolveLayersPlugins(layers, from) {
15
16
  return `${pluginsDir}/*.ts`;
16
17
  });
17
18
  }
19
+ function generateMainTs(options, vixt) {
20
+ const { buildDir, rootDir } = vixt.options;
21
+ const layersPluginsPath = resolveLayersPlugins(vixt._layers, path.join(rootDir, buildDir));
22
+ const cssTemplate = options?.css?.map((e) => `import '${e}'`).join("\n");
23
+ const code = `/** Generated by Vixt */
24
+ // @ts-nocheck
25
+ import { createSSRApp } from 'vue'
26
+ import * as Pinia from 'pinia'
27
+ import { createUnistorage } from 'pinia-plugin-unistorage'
28
+ import { pages } from 'virtual:uni-pages'
29
+ import App from '@/App.vue'
30
+
31
+ ${cssTemplate}
32
+
33
+ export function createApp() {
34
+ const app = createSSRApp(App)
35
+ const pinia = Pinia.createPinia()
36
+ pinia.use(createUnistorage())
37
+ app.use(pinia)
38
+
39
+ // install all plugins under 'plugins/'
40
+ const plugins = import.meta.glob(${JSON.stringify(layersPluginsPath)}, { import: 'default', eager: true })
41
+ // @ts-ignore
42
+ Object.values(plugins).forEach((plugin) => typeof plugin === 'function' && plugin({ app, routes: pages, pinia }))
43
+ return { app, Pinia }
44
+ }
45
+ `;
46
+ fs.outputFileSync(path.resolve(rootDir, buildDir, "main.ts"), code);
47
+ return code;
48
+ }
18
49
  const name$1 = "vixt:entry";
19
50
  const entry = defineVixtModule({
20
51
  meta: { name: name$1, configKey: "app" },
@@ -22,39 +53,16 @@ const entry = defineVixtModule({
22
53
  css: ["virtual:uno.css"]
23
54
  },
24
55
  setup(options, vixt) {
25
- let config;
56
+ generateMainTs(options, vixt);
26
57
  return {
27
58
  name: "vixt:entry",
28
59
  enforce: "pre",
29
- configResolved(_config) {
30
- config = _config;
31
- },
32
60
  transform(code, id) {
33
- const mainPath = path.resolve(config.root, "src/main.ts");
61
+ const { buildDir, rootDir } = vixt.options;
62
+ const mainPath = path.resolve(rootDir, options.main);
34
63
  if (id !== mainPath)
35
64
  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
- );
65
+ code = fs.readFileSync(path.resolve(rootDir, buildDir, "main.ts"), "utf-8");
58
66
  return code;
59
67
  }
60
68
  };
@@ -130,7 +138,8 @@ const defaults = {
130
138
  },
131
139
  typescript: {
132
140
  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"] } }
141
+ tsConfig: { compilerOptions: { types: ["@dcloudio/types", "@uni-helper/vite-plugin-uni-pages/client"] } },
142
+ typeCheck: { vueTsc: true }
134
143
  }
135
144
  };
136
145
  const index = createVixtPlugin({ defaults });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/uni",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
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.5"
34
+ "@vixt/core": "0.0.6"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "unbuild"