@vixt/core 0.0.2 → 0.0.3
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 +163 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.mjs +374 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { PluginOption, UserConfig, TransformResult, ProxyOptions } from 'vite';
|
|
3
|
+
import * as c12 from 'c12';
|
|
4
|
+
import { ConfigLayer, LoadConfigOptions } from 'c12';
|
|
5
|
+
import { TSConfig } from 'pkg-types';
|
|
6
|
+
import Checker from 'vite-plugin-checker';
|
|
7
|
+
|
|
8
|
+
declare const alias: VixtModule<ModuleOptions>;
|
|
9
|
+
|
|
10
|
+
interface Vixt {
|
|
11
|
+
options: VixtOptions;
|
|
12
|
+
_layers: VixtConfigLayer[];
|
|
13
|
+
_modules: VixtModule[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
|
|
17
|
+
type ModuleOptions = Record<string, any>;
|
|
18
|
+
interface ModuleMeta extends Record<string, any> {
|
|
19
|
+
name?: string;
|
|
20
|
+
configKey?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
|
|
23
|
+
meta?: ModuleMeta;
|
|
24
|
+
defaults?: T | ((vixt: Vixt) => T);
|
|
25
|
+
setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption;
|
|
26
|
+
}
|
|
27
|
+
interface VixtModule<T extends ModuleOptions = ModuleOptions> {
|
|
28
|
+
(this: void, inlineOptions: T, vixt: Vixt): PluginOption;
|
|
29
|
+
getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
|
|
30
|
+
getMeta?: () => ModuleMeta;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface VixtOptions extends Record<string, any> {
|
|
34
|
+
/**
|
|
35
|
+
* @default '.vixt'
|
|
36
|
+
*/
|
|
37
|
+
buildDir?: string;
|
|
38
|
+
/**
|
|
39
|
+
* @default '.vixt/types'
|
|
40
|
+
*/
|
|
41
|
+
buildTypesDir?: string;
|
|
42
|
+
/** layers */
|
|
43
|
+
extends?: string[];
|
|
44
|
+
/** modules */
|
|
45
|
+
modules?: VixtModule[];
|
|
46
|
+
vite?: UserConfig;
|
|
47
|
+
}
|
|
48
|
+
interface VixtConfigLayer extends ConfigLayer<VixtOptions> {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module '@vixt/core' {
|
|
52
|
+
interface VixtOptions {
|
|
53
|
+
app?: AppOptions;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
type Property = Record<string, string>;
|
|
57
|
+
interface AppHead {
|
|
58
|
+
meta?: Property[];
|
|
59
|
+
link?: Property[];
|
|
60
|
+
style?: Property[];
|
|
61
|
+
script?: Property[];
|
|
62
|
+
title?: Property[];
|
|
63
|
+
noscript?: Property[];
|
|
64
|
+
}
|
|
65
|
+
interface AppOptions {
|
|
66
|
+
head?: AppHead;
|
|
67
|
+
/**
|
|
68
|
+
* @default BASE_URL=/
|
|
69
|
+
*/
|
|
70
|
+
baseURL?: string;
|
|
71
|
+
/**
|
|
72
|
+
* @default '#app'
|
|
73
|
+
*/
|
|
74
|
+
rootId?: string;
|
|
75
|
+
/**
|
|
76
|
+
* @default 'div'
|
|
77
|
+
*/
|
|
78
|
+
rootTag?: string;
|
|
79
|
+
/**
|
|
80
|
+
* @default '<buildDir>/main.ts'
|
|
81
|
+
*/
|
|
82
|
+
main?: string;
|
|
83
|
+
transformMain?: (vixt: Vixt) => Promise<TransformResult | string | null | void> | TransformResult | string | null | void;
|
|
84
|
+
css?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* @default './loading.html'
|
|
87
|
+
*/
|
|
88
|
+
loadingTemplate?: string;
|
|
89
|
+
}
|
|
90
|
+
declare const app: VixtModule<AppOptions>;
|
|
91
|
+
|
|
92
|
+
declare const config: VixtModule<ModuleOptions>;
|
|
93
|
+
|
|
94
|
+
declare module '@vixt/core' {
|
|
95
|
+
interface VixtOptions {
|
|
96
|
+
devProxy?: DevProxyOptions;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
interface DevProxyOptions {
|
|
100
|
+
/**
|
|
101
|
+
* 环境变量的 key
|
|
102
|
+
* @default 'VITE_PROXY'
|
|
103
|
+
*/
|
|
104
|
+
key?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param list [prefix,target,rewrite?][]
|
|
108
|
+
*/
|
|
109
|
+
declare function transformProxy(list: string): {
|
|
110
|
+
[k: string]: ProxyOptions;
|
|
111
|
+
};
|
|
112
|
+
/** 为 vite 开发服务添加代理配置 */
|
|
113
|
+
declare const devProxy: VixtModule<DevProxyOptions>;
|
|
114
|
+
|
|
115
|
+
declare module '@vixt/core' {
|
|
116
|
+
interface VixtOptions {
|
|
117
|
+
typescript?: TypescriptOptions;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
interface TypescriptOptions {
|
|
121
|
+
references?: (string | {
|
|
122
|
+
path?: string;
|
|
123
|
+
content?: string;
|
|
124
|
+
})[];
|
|
125
|
+
tsConfig?: TSConfig;
|
|
126
|
+
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
127
|
+
typeCheck?: Parameters<typeof Checker>[0] | false;
|
|
128
|
+
}
|
|
129
|
+
declare const typescript: VixtModule<TypescriptOptions>;
|
|
130
|
+
|
|
131
|
+
declare module '@vixt/core' {
|
|
132
|
+
interface VixtOptions {
|
|
133
|
+
warmup?: WarmupOptions;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
interface WarmupOptions {
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* The files to be transformed and used on the client-side. Supports glob patterns.
|
|
140
|
+
*/
|
|
141
|
+
clientFiles?: string[];
|
|
142
|
+
/**
|
|
143
|
+
* The files to be transformed and used in SSR. Supports glob patterns.
|
|
144
|
+
*/
|
|
145
|
+
ssrFiles?: string[];
|
|
146
|
+
}
|
|
147
|
+
declare const warmup: VixtModule<WarmupOptions>;
|
|
148
|
+
|
|
149
|
+
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
150
|
+
declare const buildDir = ".vixt";
|
|
151
|
+
declare const buildTypesDir = ".vixt/types";
|
|
152
|
+
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
|
|
153
|
+
declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
|
|
154
|
+
|
|
155
|
+
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
156
|
+
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
157
|
+
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
158
|
+
declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModule[]>;
|
|
159
|
+
|
|
160
|
+
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
161
|
+
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
162
|
+
|
|
163
|
+
export { type AppHead, type AppOptions, type DevProxyOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, type WarmupOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, transformProxy, typescript, warmup };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { PluginOption, UserConfig, TransformResult, ProxyOptions } from 'vite';
|
|
3
|
+
import * as c12 from 'c12';
|
|
4
|
+
import { ConfigLayer, LoadConfigOptions } from 'c12';
|
|
5
|
+
import { TSConfig } from 'pkg-types';
|
|
6
|
+
import Checker from 'vite-plugin-checker';
|
|
7
|
+
|
|
8
|
+
declare const alias: VixtModule<ModuleOptions>;
|
|
9
|
+
|
|
10
|
+
interface Vixt {
|
|
11
|
+
options: VixtOptions;
|
|
12
|
+
_layers: VixtConfigLayer[];
|
|
13
|
+
_modules: VixtModule[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
|
|
17
|
+
type ModuleOptions = Record<string, any>;
|
|
18
|
+
interface ModuleMeta extends Record<string, any> {
|
|
19
|
+
name?: string;
|
|
20
|
+
configKey?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
|
|
23
|
+
meta?: ModuleMeta;
|
|
24
|
+
defaults?: T | ((vixt: Vixt) => T);
|
|
25
|
+
setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption;
|
|
26
|
+
}
|
|
27
|
+
interface VixtModule<T extends ModuleOptions = ModuleOptions> {
|
|
28
|
+
(this: void, inlineOptions: T, vixt: Vixt): PluginOption;
|
|
29
|
+
getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
|
|
30
|
+
getMeta?: () => ModuleMeta;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface VixtOptions extends Record<string, any> {
|
|
34
|
+
/**
|
|
35
|
+
* @default '.vixt'
|
|
36
|
+
*/
|
|
37
|
+
buildDir?: string;
|
|
38
|
+
/**
|
|
39
|
+
* @default '.vixt/types'
|
|
40
|
+
*/
|
|
41
|
+
buildTypesDir?: string;
|
|
42
|
+
/** layers */
|
|
43
|
+
extends?: string[];
|
|
44
|
+
/** modules */
|
|
45
|
+
modules?: VixtModule[];
|
|
46
|
+
vite?: UserConfig;
|
|
47
|
+
}
|
|
48
|
+
interface VixtConfigLayer extends ConfigLayer<VixtOptions> {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module '@vixt/core' {
|
|
52
|
+
interface VixtOptions {
|
|
53
|
+
app?: AppOptions;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
type Property = Record<string, string>;
|
|
57
|
+
interface AppHead {
|
|
58
|
+
meta?: Property[];
|
|
59
|
+
link?: Property[];
|
|
60
|
+
style?: Property[];
|
|
61
|
+
script?: Property[];
|
|
62
|
+
title?: Property[];
|
|
63
|
+
noscript?: Property[];
|
|
64
|
+
}
|
|
65
|
+
interface AppOptions {
|
|
66
|
+
head?: AppHead;
|
|
67
|
+
/**
|
|
68
|
+
* @default BASE_URL=/
|
|
69
|
+
*/
|
|
70
|
+
baseURL?: string;
|
|
71
|
+
/**
|
|
72
|
+
* @default '#app'
|
|
73
|
+
*/
|
|
74
|
+
rootId?: string;
|
|
75
|
+
/**
|
|
76
|
+
* @default 'div'
|
|
77
|
+
*/
|
|
78
|
+
rootTag?: string;
|
|
79
|
+
/**
|
|
80
|
+
* @default '<buildDir>/main.ts'
|
|
81
|
+
*/
|
|
82
|
+
main?: string;
|
|
83
|
+
transformMain?: (vixt: Vixt) => Promise<TransformResult | string | null | void> | TransformResult | string | null | void;
|
|
84
|
+
css?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* @default './loading.html'
|
|
87
|
+
*/
|
|
88
|
+
loadingTemplate?: string;
|
|
89
|
+
}
|
|
90
|
+
declare const app: VixtModule<AppOptions>;
|
|
91
|
+
|
|
92
|
+
declare const config: VixtModule<ModuleOptions>;
|
|
93
|
+
|
|
94
|
+
declare module '@vixt/core' {
|
|
95
|
+
interface VixtOptions {
|
|
96
|
+
devProxy?: DevProxyOptions;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
interface DevProxyOptions {
|
|
100
|
+
/**
|
|
101
|
+
* 环境变量的 key
|
|
102
|
+
* @default 'VITE_PROXY'
|
|
103
|
+
*/
|
|
104
|
+
key?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param list [prefix,target,rewrite?][]
|
|
108
|
+
*/
|
|
109
|
+
declare function transformProxy(list: string): {
|
|
110
|
+
[k: string]: ProxyOptions;
|
|
111
|
+
};
|
|
112
|
+
/** 为 vite 开发服务添加代理配置 */
|
|
113
|
+
declare const devProxy: VixtModule<DevProxyOptions>;
|
|
114
|
+
|
|
115
|
+
declare module '@vixt/core' {
|
|
116
|
+
interface VixtOptions {
|
|
117
|
+
typescript?: TypescriptOptions;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
interface TypescriptOptions {
|
|
121
|
+
references?: (string | {
|
|
122
|
+
path?: string;
|
|
123
|
+
content?: string;
|
|
124
|
+
})[];
|
|
125
|
+
tsConfig?: TSConfig;
|
|
126
|
+
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
127
|
+
typeCheck?: Parameters<typeof Checker>[0] | false;
|
|
128
|
+
}
|
|
129
|
+
declare const typescript: VixtModule<TypescriptOptions>;
|
|
130
|
+
|
|
131
|
+
declare module '@vixt/core' {
|
|
132
|
+
interface VixtOptions {
|
|
133
|
+
warmup?: WarmupOptions;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
interface WarmupOptions {
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* The files to be transformed and used on the client-side. Supports glob patterns.
|
|
140
|
+
*/
|
|
141
|
+
clientFiles?: string[];
|
|
142
|
+
/**
|
|
143
|
+
* The files to be transformed and used in SSR. Supports glob patterns.
|
|
144
|
+
*/
|
|
145
|
+
ssrFiles?: string[];
|
|
146
|
+
}
|
|
147
|
+
declare const warmup: VixtModule<WarmupOptions>;
|
|
148
|
+
|
|
149
|
+
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
150
|
+
declare const buildDir = ".vixt";
|
|
151
|
+
declare const buildTypesDir = ".vixt/types";
|
|
152
|
+
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
|
|
153
|
+
declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
|
|
154
|
+
|
|
155
|
+
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
156
|
+
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
157
|
+
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
158
|
+
declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModule[]>;
|
|
159
|
+
|
|
160
|
+
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
161
|
+
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
162
|
+
|
|
163
|
+
export { type AppHead, type AppOptions, type DevProxyOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, type WarmupOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, transformProxy, typescript, warmup };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { cwd } from 'node:process';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import 'tsx/esm';
|
|
5
|
+
import { pathToFileURL } from 'mlly';
|
|
6
|
+
import defu from 'defu';
|
|
7
|
+
import Checker from 'vite-plugin-checker';
|
|
8
|
+
import { loadConfig } from 'c12';
|
|
9
|
+
|
|
10
|
+
const name$5 = "vixt:alias";
|
|
11
|
+
const alias = defineVixtModule({
|
|
12
|
+
meta: { name: name$5 },
|
|
13
|
+
setup() {
|
|
14
|
+
return {
|
|
15
|
+
name: name$5,
|
|
16
|
+
config() {
|
|
17
|
+
return {
|
|
18
|
+
resolve: {
|
|
19
|
+
alias: {
|
|
20
|
+
"@": `${path.resolve(cwd(), "src")}`,
|
|
21
|
+
"~": `${path.resolve(cwd(), "src")}`,
|
|
22
|
+
"@@": path.resolve(cwd()),
|
|
23
|
+
"~~": path.resolve(cwd())
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function defineVitePlugin(pluginFn) {
|
|
33
|
+
return pluginFn;
|
|
34
|
+
}
|
|
35
|
+
function defineVixtModule(definition) {
|
|
36
|
+
if (typeof definition == "function")
|
|
37
|
+
return defineVixtModule({ setup: definition });
|
|
38
|
+
const module = definition;
|
|
39
|
+
function getOptions(inlineOptions, vixt) {
|
|
40
|
+
const configKey = module.meta?.configKey || module.meta?.name;
|
|
41
|
+
const defaultOptions = typeof module.defaults === "function" ? module.defaults(vixt) : module.defaults;
|
|
42
|
+
const resolvedOptions = defu(inlineOptions, configKey ? vixt.options[configKey] : {}, defaultOptions);
|
|
43
|
+
return resolvedOptions;
|
|
44
|
+
}
|
|
45
|
+
function normalizedModule(inlineOptions, vixt) {
|
|
46
|
+
return module.setup?.(getOptions(inlineOptions, vixt), vixt);
|
|
47
|
+
}
|
|
48
|
+
normalizedModule.getMeta = () => module.meta;
|
|
49
|
+
normalizedModule.getOptions = getOptions;
|
|
50
|
+
return normalizedModule;
|
|
51
|
+
}
|
|
52
|
+
function installModule(module, inlineOptions, vixt) {
|
|
53
|
+
return module(inlineOptions, vixt);
|
|
54
|
+
}
|
|
55
|
+
async function applyLayerModules(layers) {
|
|
56
|
+
const { modules: modulesDir = [] } = resolveLayersDirs(layers);
|
|
57
|
+
const modules = [];
|
|
58
|
+
for (const m of modulesDir) {
|
|
59
|
+
if (fs.existsSync(m)) {
|
|
60
|
+
const files = fs.readdirSync(m);
|
|
61
|
+
for (const f of files) {
|
|
62
|
+
const p = path.resolve(m, f);
|
|
63
|
+
const module = await import(
|
|
64
|
+
/* @vite-ignore */
|
|
65
|
+
pathToFileURL(p)
|
|
66
|
+
).then((m2) => m2.default);
|
|
67
|
+
modules.push(module);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return modules;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function defineVixtConfig(input) {
|
|
75
|
+
return input;
|
|
76
|
+
}
|
|
77
|
+
const buildDir = ".vixt";
|
|
78
|
+
const buildTypesDir = `${buildDir}/types`;
|
|
79
|
+
function loadVixtConfig(opts) {
|
|
80
|
+
return loadConfig({
|
|
81
|
+
name: "vixt",
|
|
82
|
+
...opts,
|
|
83
|
+
defaults: {
|
|
84
|
+
buildDir,
|
|
85
|
+
buildTypesDir,
|
|
86
|
+
...opts?.defaults
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function resolveLayersDirs(layers) {
|
|
91
|
+
const dirs = {};
|
|
92
|
+
for (const layer of layers?.filter((e) => e.cwd) ?? []) {
|
|
93
|
+
const contents = fs.readdirSync(path.resolve(layer.cwd, "src"));
|
|
94
|
+
for (const content of contents) {
|
|
95
|
+
const fileOrDirPath = path.resolve(layer.cwd, "src", content);
|
|
96
|
+
if (fs.statSync(fileOrDirPath).isDirectory()) {
|
|
97
|
+
dirs[content] ?? (dirs[content] = []);
|
|
98
|
+
dirs[content].push(fileOrDirPath);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return dirs;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resolveHeadTag(tag, attrs) {
|
|
106
|
+
const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
|
|
107
|
+
return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
|
|
108
|
+
}
|
|
109
|
+
function generateIndexHtml(options, vixt, config) {
|
|
110
|
+
const { buildDir: buildDir2 } = vixt.options;
|
|
111
|
+
const { head = {}, rootTag, rootId, main, loadingTemplate: loading = "" } = options || {};
|
|
112
|
+
const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
113
|
+
const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
114
|
+
let loadingTemplate = "";
|
|
115
|
+
if (/^\.|\//.test(loading)) {
|
|
116
|
+
const loadingTemplatePath = path.resolve(config.root, loading);
|
|
117
|
+
if (fs.existsSync(loadingTemplatePath)) {
|
|
118
|
+
loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
|
|
119
|
+
}
|
|
120
|
+
} else if (loading) {
|
|
121
|
+
loadingTemplate = loading;
|
|
122
|
+
}
|
|
123
|
+
const code = `
|
|
124
|
+
<!doctype html>
|
|
125
|
+
<html>
|
|
126
|
+
<head>
|
|
127
|
+
${headTemplate}
|
|
128
|
+
</head>
|
|
129
|
+
<body>
|
|
130
|
+
<${rootTag} id="${rootId}">
|
|
131
|
+
${loadingTemplate}
|
|
132
|
+
</${rootTag}>
|
|
133
|
+
<script type="module" src="${main}"><\/script>
|
|
134
|
+
${noscriptTemplate}
|
|
135
|
+
</body>
|
|
136
|
+
</html>
|
|
137
|
+
`;
|
|
138
|
+
fs.outputFileSync(path.resolve(config.root, `${buildDir2}/index.html`), code);
|
|
139
|
+
return code;
|
|
140
|
+
}
|
|
141
|
+
const name$4 = "vixt:app";
|
|
142
|
+
const defaults$2 = {
|
|
143
|
+
rootId: "app",
|
|
144
|
+
rootTag: "div",
|
|
145
|
+
loadingTemplate: "./loading.html",
|
|
146
|
+
main: `${buildDir}/main.ts`,
|
|
147
|
+
head: {
|
|
148
|
+
meta: [
|
|
149
|
+
{ charset: "utf-8" },
|
|
150
|
+
{ name: "viewport", content: "width=device-width, initial-scale=1.0" }
|
|
151
|
+
],
|
|
152
|
+
noscript: [{ children: "This website requires JavaScript to function properly. Please enable JavaScript to continue." }]
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const app = defineVixtModule({
|
|
156
|
+
meta: { name: name$4, configKey: "app" },
|
|
157
|
+
defaults: defaults$2,
|
|
158
|
+
setup(options, vixt) {
|
|
159
|
+
return {
|
|
160
|
+
name: name$4,
|
|
161
|
+
configResolved(config) {
|
|
162
|
+
generateIndexHtml(options, vixt, config);
|
|
163
|
+
},
|
|
164
|
+
transformIndexHtml: {
|
|
165
|
+
order: "pre",
|
|
166
|
+
handler() {
|
|
167
|
+
const { buildDir: buildDir2 } = vixt.options;
|
|
168
|
+
return fs.readFileSync(path.resolve(cwd(), `${buildDir2}/index.html`), { encoding: "utf-8" });
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
transform: {
|
|
172
|
+
order: "pre",
|
|
173
|
+
handler(code, id) {
|
|
174
|
+
if (!id.includes(options.main))
|
|
175
|
+
return;
|
|
176
|
+
return options.transformMain?.(vixt);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const name$3 = "vixt:config";
|
|
184
|
+
const config = defineVixtModule({
|
|
185
|
+
meta: { name: name$3 },
|
|
186
|
+
setup(options, vixt) {
|
|
187
|
+
return {
|
|
188
|
+
name: name$3,
|
|
189
|
+
enforce: "pre",
|
|
190
|
+
config(config2) {
|
|
191
|
+
vixt.options.vite = config2;
|
|
192
|
+
},
|
|
193
|
+
configResolved(config2) {
|
|
194
|
+
vixt.options.vite = config2;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
function transformProxy(list) {
|
|
201
|
+
return Object.fromEntries(
|
|
202
|
+
JSON.parse(list).map(([prefix, target, rewrite]) => {
|
|
203
|
+
const option = {
|
|
204
|
+
target,
|
|
205
|
+
changeOrigin: true,
|
|
206
|
+
ws: true,
|
|
207
|
+
secure: /^https:\/\//.test(target)
|
|
208
|
+
};
|
|
209
|
+
if (rewrite)
|
|
210
|
+
option.rewrite = (path) => path.replace(new RegExp(`^${prefix}`), "");
|
|
211
|
+
return [prefix, option];
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
const name$2 = "vixt:dev-proxy";
|
|
216
|
+
const devProxy = defineVixtModule({
|
|
217
|
+
meta: { name: name$2, configKey: "devProxy" },
|
|
218
|
+
defaults: { key: "VITE_PROXY" },
|
|
219
|
+
setup(options) {
|
|
220
|
+
return {
|
|
221
|
+
name: name$2,
|
|
222
|
+
configResolved(config) {
|
|
223
|
+
const { env } = config;
|
|
224
|
+
const proxyList = env[options.key];
|
|
225
|
+
if (proxyList) {
|
|
226
|
+
const proxy = transformProxy(proxyList);
|
|
227
|
+
config.server.proxy = defu(proxy, config.server.proxy);
|
|
228
|
+
config.preview.proxy = defu(proxy, config.server.proxy);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
function generateDts(options, vixt, config) {
|
|
236
|
+
const { root } = config;
|
|
237
|
+
const { buildDir } = vixt.options;
|
|
238
|
+
const vixtDts = options.references?.map((reference) => {
|
|
239
|
+
if (typeof reference === "string") {
|
|
240
|
+
return `/// <reference path="${reference}" />`;
|
|
241
|
+
} else if (typeof reference === "object" && reference.path && reference.content) {
|
|
242
|
+
fs.outputFileSync(path.resolve(root, buildDir), reference.content ?? "");
|
|
243
|
+
return `/// <reference path="${reference.path}" />`;
|
|
244
|
+
} else {
|
|
245
|
+
return "";
|
|
246
|
+
}
|
|
247
|
+
}).concat("export {}").join("\n");
|
|
248
|
+
const vixtDtsPath = path.resolve(root, buildDir, "vixt.d.ts");
|
|
249
|
+
fs.outputFileSync(vixtDtsPath, vixtDts);
|
|
250
|
+
}
|
|
251
|
+
function generateTsConfig(options, vixt, config) {
|
|
252
|
+
const { root } = config;
|
|
253
|
+
const { buildDir } = vixt.options;
|
|
254
|
+
const tsConfigPath = path.resolve(root, buildDir, "tsconfig.json");
|
|
255
|
+
const layersDirs = vixt._layers.filter((e) => e.cwd).map((e) => e.cwd);
|
|
256
|
+
const tsConfig = defu(options.tsConfig, { include: layersDirs });
|
|
257
|
+
fs.outputFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
|
|
258
|
+
}
|
|
259
|
+
function generateEnvDts(options, vixt, config) {
|
|
260
|
+
const { env, root } = config;
|
|
261
|
+
const { buildDir } = vixt.options;
|
|
262
|
+
const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
|
|
263
|
+
${key}: ${typeof value}`).join("\n ");
|
|
264
|
+
const envDts = `interface ImportMeta {
|
|
265
|
+
readonly env: ImportMetaEnv
|
|
266
|
+
}
|
|
267
|
+
interface ImportMetaEnv {
|
|
268
|
+
${values}
|
|
269
|
+
}
|
|
270
|
+
`;
|
|
271
|
+
const envDtsPath = path.resolve(root, buildDir, "types", "vite-env.d.ts");
|
|
272
|
+
fs.outputFileSync(envDtsPath, envDts);
|
|
273
|
+
}
|
|
274
|
+
function genarateShims(options, vixt, config) {
|
|
275
|
+
const { root } = config;
|
|
276
|
+
const { buildDir } = vixt.options;
|
|
277
|
+
const shimsDts = `
|
|
278
|
+
declare module '*.vue' {
|
|
279
|
+
import type { DefineComponent } from 'vue'
|
|
280
|
+
|
|
281
|
+
const component: DefineComponent
|
|
282
|
+
export default component
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
const shimsDtsPath = path.resolve(root, buildDir, "types", "shims.d.ts");
|
|
286
|
+
fs.outputFileSync(shimsDtsPath, shimsDts);
|
|
287
|
+
}
|
|
288
|
+
const name$1 = "vixt:typescript";
|
|
289
|
+
const defaults$1 = {
|
|
290
|
+
references: ["./types/vite-env.d.ts", "./types/shims.d.ts"],
|
|
291
|
+
tsConfig: {
|
|
292
|
+
extends: "@vue/tsconfig/tsconfig.dom.json",
|
|
293
|
+
compilerOptions: {
|
|
294
|
+
paths: {
|
|
295
|
+
"@": ["../src"],
|
|
296
|
+
"@/*": ["../src/*"],
|
|
297
|
+
"~": ["../src"],
|
|
298
|
+
"~/*": ["../src/*"]
|
|
299
|
+
},
|
|
300
|
+
types: ["vite/client"]
|
|
301
|
+
},
|
|
302
|
+
include: [
|
|
303
|
+
"./**/*"
|
|
304
|
+
]
|
|
305
|
+
},
|
|
306
|
+
typeCheck: { vueTsc: true, enableBuild: false, overlay: { initialIsOpen: false } }
|
|
307
|
+
};
|
|
308
|
+
const typescript = defineVixtModule({
|
|
309
|
+
meta: { name: name$1, configKey: "typescript" },
|
|
310
|
+
defaults: defaults$1,
|
|
311
|
+
setup(options, vixt) {
|
|
312
|
+
return [
|
|
313
|
+
{
|
|
314
|
+
name: name$1,
|
|
315
|
+
configResolved(config) {
|
|
316
|
+
generateDts(options, vixt, config);
|
|
317
|
+
generateTsConfig(options, vixt, config);
|
|
318
|
+
generateEnvDts(options, vixt, config);
|
|
319
|
+
genarateShims(options, vixt, config);
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
options.typeCheck && Checker(options.typeCheck)
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const defaults = {
|
|
328
|
+
enabled: true,
|
|
329
|
+
clientFiles: ["./index.html", "./src/**/*.vue", "./src/**/*.ts", "./src/**/*.tsx"],
|
|
330
|
+
ssrFiles: ["./index.html", "./src/**/*.vue", "./src/**/*.ts", "./src/**/*.tsx"]
|
|
331
|
+
};
|
|
332
|
+
const name = "vixt:warmup";
|
|
333
|
+
const warmup = defineVixtModule({
|
|
334
|
+
meta: { name, configKey: "warmup" },
|
|
335
|
+
defaults,
|
|
336
|
+
setup(options) {
|
|
337
|
+
return {
|
|
338
|
+
name,
|
|
339
|
+
config() {
|
|
340
|
+
if (!options.enabled)
|
|
341
|
+
return;
|
|
342
|
+
return {
|
|
343
|
+
server: {
|
|
344
|
+
warmup: options
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
async function loadVixt(opts) {
|
|
353
|
+
const result = await loadVixtConfig(defu(opts, {
|
|
354
|
+
defaults: {
|
|
355
|
+
modules: [alias, app, config, devProxy, typescript, warmup]
|
|
356
|
+
}
|
|
357
|
+
}));
|
|
358
|
+
const layerModules = await applyLayerModules(result.layers);
|
|
359
|
+
const vixt = {
|
|
360
|
+
options: result.config,
|
|
361
|
+
_layers: result.layers ?? [],
|
|
362
|
+
_modules: [...result.config.modules ?? [], ...layerModules]
|
|
363
|
+
};
|
|
364
|
+
return vixt;
|
|
365
|
+
}
|
|
366
|
+
function createVixtPlugin(loadOptions) {
|
|
367
|
+
return defineVitePlugin(async (vixtOptions) => {
|
|
368
|
+
const vixt = await loadVixt(defu({ defaults: vixtOptions }, loadOptions));
|
|
369
|
+
const plugins = vixt._modules.map((module) => module({}, vixt));
|
|
370
|
+
return plugins;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export { alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, transformProxy, typescript, warmup };
|