@vixt/uni 0.0.5 → 0.0.7
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 +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.mjs +54 -33
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import * as _vixt_core from '@vixt/core';
|
|
3
|
+
import { AppOptions, PluginOptions, VixtOptions } from '@vixt/core';
|
|
4
|
+
import Uni from '@dcloudio/vite-plugin-uni';
|
|
5
|
+
import Pages from '@uni-helper/vite-plugin-uni-pages';
|
|
6
|
+
import Components from '@uni-helper/vite-plugin-uni-components';
|
|
7
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
|
8
|
+
import UnoCSS from 'unocss/vite';
|
|
9
|
+
|
|
10
|
+
declare const entryUni: _vixt_core.VixtModule<AppOptions>;
|
|
11
|
+
|
|
12
|
+
declare module '@vixt/core' {
|
|
13
|
+
interface VixtOptions {
|
|
14
|
+
uni?: PluginOptions<typeof Uni>;
|
|
15
|
+
/** https://github.com/uni-helper/vite-plugin-uni-pages */
|
|
16
|
+
pages?: PluginOptions<typeof Pages>;
|
|
17
|
+
/** https://github.com/uni-helper/vite-plugin-uni-layouts */
|
|
18
|
+
layouts?: any;
|
|
19
|
+
/** https://github.com/uni-helper/vite-plugin-uni-components */
|
|
20
|
+
components?: PluginOptions<typeof Components>;
|
|
21
|
+
/** https://github.com/antfu/unplugin-auto-import */
|
|
22
|
+
imports?: PluginOptions<typeof AutoImport>;
|
|
23
|
+
/** https://github.com/antfu/unocss */
|
|
24
|
+
unocss?: PluginOptions<typeof UnoCSS>;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
|
|
28
|
+
|
|
29
|
+
/** 增加小程序中vueuse的运行所需 */
|
|
30
|
+
declare function vueusePolyfill(code: string, id: string): string;
|
|
31
|
+
/** 移除路径中的'../' */
|
|
32
|
+
declare function patchNormalizeNodeModules(): void;
|
|
33
|
+
declare const uniPatch: (options?: any) => vite.PluginOption;
|
|
3
34
|
|
|
4
35
|
declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
|
|
5
36
|
|
|
6
|
-
export { _default as default };
|
|
37
|
+
export { _default as default, entryUni, patchNormalizeNodeModules, presetUni, uniPatch, vueusePolyfill };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import * as _vixt_core from '@vixt/core';
|
|
3
|
+
import { AppOptions, PluginOptions, VixtOptions } from '@vixt/core';
|
|
4
|
+
import Uni from '@dcloudio/vite-plugin-uni';
|
|
5
|
+
import Pages from '@uni-helper/vite-plugin-uni-pages';
|
|
6
|
+
import Components from '@uni-helper/vite-plugin-uni-components';
|
|
7
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
|
8
|
+
import UnoCSS from 'unocss/vite';
|
|
9
|
+
|
|
10
|
+
declare const entryUni: _vixt_core.VixtModule<AppOptions>;
|
|
11
|
+
|
|
12
|
+
declare module '@vixt/core' {
|
|
13
|
+
interface VixtOptions {
|
|
14
|
+
uni?: PluginOptions<typeof Uni>;
|
|
15
|
+
/** https://github.com/uni-helper/vite-plugin-uni-pages */
|
|
16
|
+
pages?: PluginOptions<typeof Pages>;
|
|
17
|
+
/** https://github.com/uni-helper/vite-plugin-uni-layouts */
|
|
18
|
+
layouts?: any;
|
|
19
|
+
/** https://github.com/uni-helper/vite-plugin-uni-components */
|
|
20
|
+
components?: PluginOptions<typeof Components>;
|
|
21
|
+
/** https://github.com/antfu/unplugin-auto-import */
|
|
22
|
+
imports?: PluginOptions<typeof AutoImport>;
|
|
23
|
+
/** https://github.com/antfu/unocss */
|
|
24
|
+
unocss?: PluginOptions<typeof UnoCSS>;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare const presetUni: _vixt_core.VixtModule<VixtOptions>;
|
|
28
|
+
|
|
29
|
+
/** 增加小程序中vueuse的运行所需 */
|
|
30
|
+
declare function vueusePolyfill(code: string, id: string): string;
|
|
31
|
+
/** 移除路径中的'../' */
|
|
32
|
+
declare function patchNormalizeNodeModules(): void;
|
|
33
|
+
declare const uniPatch: (options?: any) => vite.PluginOption;
|
|
3
34
|
|
|
4
35
|
declare const _default: (options?: _vixt_core.VixtOptions | undefined) => vite.PluginOption;
|
|
5
36
|
|
|
6
|
-
export { _default as default };
|
|
37
|
+
export { _default as default, entryUni, patchNormalizeNodeModules, presetUni, uniPatch, vueusePolyfill };
|
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';
|
|
@@ -7,6 +8,7 @@ import Layouts from '@uni-helper/vite-plugin-uni-layouts';
|
|
|
7
8
|
import Components from '@uni-helper/vite-plugin-uni-components';
|
|
8
9
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
9
10
|
import UnoCSS from 'unocss/vite';
|
|
11
|
+
import { resolvePathSync } from 'mlly';
|
|
10
12
|
|
|
11
13
|
function resolveLayersPlugins(layers, from) {
|
|
12
14
|
const { plugins = [] } = resolveLayersDirs(layers);
|
|
@@ -15,46 +17,53 @@ function resolveLayersPlugins(layers, from) {
|
|
|
15
17
|
return `${pluginsDir}/*.ts`;
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
+
function generateMainTs(options, vixt) {
|
|
21
|
+
const { buildDir, rootDir } = vixt.options;
|
|
22
|
+
const layersPluginsPath = resolveLayersPlugins(vixt._layers, path.join(rootDir, buildDir));
|
|
23
|
+
const cssTemplate = options?.css?.map((e) => `import '${e}'`).join("\n");
|
|
24
|
+
const code = `/** Generated by Vixt */
|
|
25
|
+
// @ts-nocheck
|
|
26
|
+
import { createSSRApp } from 'vue'
|
|
27
|
+
import * as Pinia from 'pinia'
|
|
28
|
+
import { createUnistorage } from 'pinia-plugin-unistorage'
|
|
29
|
+
import { pages } from 'virtual:uni-pages'
|
|
30
|
+
|
|
31
|
+
import App from '@/App.vue'
|
|
32
|
+
${cssTemplate}
|
|
33
|
+
|
|
34
|
+
export function createApp() {
|
|
35
|
+
const app = createSSRApp(App)
|
|
36
|
+
const pinia = Pinia.createPinia()
|
|
37
|
+
pinia.use(createUnistorage())
|
|
38
|
+
app.use(pinia)
|
|
39
|
+
|
|
40
|
+
// install all plugins under 'plugins/'
|
|
41
|
+
const plugins = import.meta.glob(${JSON.stringify(layersPluginsPath)}, { import: 'default', eager: true })
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
Object.values(plugins).forEach((plugin) => typeof plugin === 'function' && plugin({ app, routes: pages, pinia }))
|
|
44
|
+
return { app, Pinia }
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
fs.outputFileSync(path.resolve(rootDir, buildDir, "main.ts"), code);
|
|
48
|
+
return code;
|
|
49
|
+
}
|
|
50
|
+
const name$1 = "vixt:entry-uni";
|
|
51
|
+
const entryUni = defineVixtModule({
|
|
20
52
|
meta: { name: name$1, configKey: "app" },
|
|
21
53
|
defaults: {
|
|
22
54
|
css: ["virtual:uno.css"]
|
|
23
55
|
},
|
|
24
56
|
setup(options, vixt) {
|
|
25
|
-
|
|
57
|
+
generateMainTs(options, vixt);
|
|
26
58
|
return {
|
|
27
|
-
name: "vixt:entry",
|
|
59
|
+
name: "vixt:entry-uni",
|
|
28
60
|
enforce: "pre",
|
|
29
|
-
configResolved(_config) {
|
|
30
|
-
config = _config;
|
|
31
|
-
},
|
|
32
61
|
transform(code, id) {
|
|
33
|
-
const
|
|
62
|
+
const { buildDir, rootDir } = vixt.options;
|
|
63
|
+
const mainPath = path.resolve(rootDir, options.main);
|
|
34
64
|
if (id !== mainPath)
|
|
35
65
|
return;
|
|
36
|
-
|
|
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
|
-
);
|
|
66
|
+
code = fs.readFileSync(path.resolve(rootDir, buildDir, "main.ts"), "utf-8");
|
|
58
67
|
return code;
|
|
59
68
|
}
|
|
60
69
|
};
|
|
@@ -110,7 +119,18 @@ export const TransitionGroup = {}
|
|
|
110
119
|
`;
|
|
111
120
|
return code;
|
|
112
121
|
}
|
|
122
|
+
const matched = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules');`;
|
|
123
|
+
const replaced = `str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules').replace(/\\.\\.\\//g, '');`;
|
|
124
|
+
function patchNormalizeNodeModules() {
|
|
125
|
+
const codePath = resolvePathSync("@dcloudio/uni-cli-shared/dist/utils.js");
|
|
126
|
+
let code = fs.readFileSync(codePath, "utf8");
|
|
127
|
+
if (code.includes(matched)) {
|
|
128
|
+
code = code.replace(matched, replaced);
|
|
129
|
+
fs.writeFileSync(codePath, code);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
113
132
|
const uniPatch = defineVitePlugin(() => {
|
|
133
|
+
patchNormalizeNodeModules();
|
|
114
134
|
return {
|
|
115
135
|
name: "vixt:uni-patch",
|
|
116
136
|
transform(code, id) {
|
|
@@ -121,7 +141,7 @@ const uniPatch = defineVitePlugin(() => {
|
|
|
121
141
|
});
|
|
122
142
|
|
|
123
143
|
const defaults = {
|
|
124
|
-
modules: [
|
|
144
|
+
modules: [entryUni, presetUni],
|
|
125
145
|
app: {
|
|
126
146
|
head: {
|
|
127
147
|
link: [{ rel: "icon", href: "/static/favicon.ico" }]
|
|
@@ -130,9 +150,10 @@ const defaults = {
|
|
|
130
150
|
},
|
|
131
151
|
typescript: {
|
|
132
152
|
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"] } }
|
|
153
|
+
tsConfig: { compilerOptions: { types: ["@dcloudio/types", "@uni-helper/vite-plugin-uni-pages/client"] } },
|
|
154
|
+
typeCheck: { vueTsc: true }
|
|
134
155
|
}
|
|
135
156
|
};
|
|
136
157
|
const index = createVixtPlugin({ defaults });
|
|
137
158
|
|
|
138
|
-
export { index as default };
|
|
159
|
+
export { index as default, entryUni, patchNormalizeNodeModules, presetUni, uniPatch, vueusePolyfill };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixt/uni",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
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.
|
|
34
|
+
"@vixt/core": "0.0.7"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "unbuild"
|