@vixt/core 0.4.0 → 0.4.2
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/client/index.d.mts +18 -0
- package/dist/client/index.d.ts +18 -0
- package/dist/client/index.mjs +11 -0
- package/dist/node/index.d.mts +182 -0
- package/dist/node/index.d.ts +182 -0
- package/dist/node/index.mjs +450 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface VixtApp {
|
|
2
|
+
appConfig: VixtAppConfig;
|
|
3
|
+
}
|
|
4
|
+
interface VixtAppConfig extends Record<string, any> {
|
|
5
|
+
}
|
|
6
|
+
declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
|
|
7
|
+
|
|
8
|
+
interface PluginDefinition {
|
|
9
|
+
name?: string;
|
|
10
|
+
setup?: (this: void, vixt: VixtApp) => any;
|
|
11
|
+
}
|
|
12
|
+
interface VixtPlugin {
|
|
13
|
+
(this: void, vixt: VixtApp): any;
|
|
14
|
+
}
|
|
15
|
+
declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
|
|
16
|
+
|
|
17
|
+
export { defineAppConfig, defineVixtPlugin };
|
|
18
|
+
export type { PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface VixtApp {
|
|
2
|
+
appConfig: VixtAppConfig;
|
|
3
|
+
}
|
|
4
|
+
interface VixtAppConfig extends Record<string, any> {
|
|
5
|
+
}
|
|
6
|
+
declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
|
|
7
|
+
|
|
8
|
+
interface PluginDefinition {
|
|
9
|
+
name?: string;
|
|
10
|
+
setup?: (this: void, vixt: VixtApp) => any;
|
|
11
|
+
}
|
|
12
|
+
interface VixtPlugin {
|
|
13
|
+
(this: void, vixt: VixtApp): any;
|
|
14
|
+
}
|
|
15
|
+
declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
|
|
16
|
+
|
|
17
|
+
export { defineAppConfig, defineVixtPlugin };
|
|
18
|
+
export type { PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function defineAppConfig(config) {
|
|
2
|
+
return config;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function defineVixtPlugin(definition) {
|
|
6
|
+
if (typeof definition == "function")
|
|
7
|
+
return defineVixtPlugin({ setup: definition });
|
|
8
|
+
return (vixt) => definition.setup?.(vixt);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { defineAppConfig, defineVixtPlugin };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as c12 from 'c12';
|
|
2
|
+
import { LoadConfigOptions, ConfigLayer, ConfigLayerMeta } from 'c12';
|
|
3
|
+
import * as vite from 'vite';
|
|
4
|
+
import { PluginOption, ResolvedConfig } from 'vite';
|
|
5
|
+
import { RawVueCompilerOptions } from '@vue/language-core';
|
|
6
|
+
import { TSConfig } from 'pkg-types';
|
|
7
|
+
import Checker from 'vite-plugin-checker';
|
|
8
|
+
|
|
9
|
+
type Property = Record<string, string>;
|
|
10
|
+
interface AppHead {
|
|
11
|
+
meta?: Property[];
|
|
12
|
+
link?: Property[];
|
|
13
|
+
style?: Property[];
|
|
14
|
+
script?: Property[];
|
|
15
|
+
title?: Property[];
|
|
16
|
+
noscript?: Property[];
|
|
17
|
+
}
|
|
18
|
+
interface AppOptions {
|
|
19
|
+
head?: AppHead;
|
|
20
|
+
/**
|
|
21
|
+
* @default /
|
|
22
|
+
*/
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
/**
|
|
25
|
+
* @default 'app'
|
|
26
|
+
*/
|
|
27
|
+
rootId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @default 'div'
|
|
30
|
+
*/
|
|
31
|
+
rootTag?: string;
|
|
32
|
+
/** inject css files */
|
|
33
|
+
css?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* @default './loading.html'
|
|
36
|
+
*/
|
|
37
|
+
loadingTemplate?: string;
|
|
38
|
+
/**
|
|
39
|
+
* @default '/src/main.ts'(vue)
|
|
40
|
+
* @default '/src/main.tsx'(react)
|
|
41
|
+
* @example 'entry.ts'(means '/src/entry.ts') or './entry.ts'
|
|
42
|
+
*/
|
|
43
|
+
entryFile?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Vixt {
|
|
47
|
+
options: VixtOptions;
|
|
48
|
+
_layers: VixtConfigLayer[];
|
|
49
|
+
_modules: VixtModule[];
|
|
50
|
+
}
|
|
51
|
+
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
52
|
+
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
53
|
+
|
|
54
|
+
type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
|
|
55
|
+
type ModuleOptions = Record<string, any>;
|
|
56
|
+
interface ModuleMeta extends Record<string, any> {
|
|
57
|
+
name?: string;
|
|
58
|
+
configKey?: string;
|
|
59
|
+
}
|
|
60
|
+
interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
|
|
61
|
+
meta?: ModuleMeta;
|
|
62
|
+
defaults?: T | ((vixt: Vixt) => T);
|
|
63
|
+
setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
|
|
64
|
+
}
|
|
65
|
+
interface VixtModule<T extends ModuleOptions = ModuleOptions> {
|
|
66
|
+
(this: void, inlineOptions: T, vixt: Vixt): PluginOption;
|
|
67
|
+
getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
|
|
68
|
+
getMeta?: () => ModuleMeta;
|
|
69
|
+
}
|
|
70
|
+
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
71
|
+
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
72
|
+
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
73
|
+
declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
|
|
74
|
+
|
|
75
|
+
interface VixtOptions extends Record<string, any> {
|
|
76
|
+
/**
|
|
77
|
+
* @default process.cwd()
|
|
78
|
+
*/
|
|
79
|
+
rootDir?: string;
|
|
80
|
+
/**
|
|
81
|
+
* @default '<rootDir>/.vixt'
|
|
82
|
+
*/
|
|
83
|
+
buildDir?: string;
|
|
84
|
+
/**
|
|
85
|
+
* @default '<buildDir>/types'
|
|
86
|
+
*/
|
|
87
|
+
buildTypesDir?: string;
|
|
88
|
+
/**
|
|
89
|
+
* @default '<buildDir>/layers'
|
|
90
|
+
*/
|
|
91
|
+
buildLayersDir?: string;
|
|
92
|
+
/**
|
|
93
|
+
* @default '<buildDir>/imports'
|
|
94
|
+
*/
|
|
95
|
+
buildImportsDir?: string;
|
|
96
|
+
/**
|
|
97
|
+
* @default '<rootDir>/src'
|
|
98
|
+
*/
|
|
99
|
+
srcDir?: string;
|
|
100
|
+
/** modules */
|
|
101
|
+
modules?: VixtModule[];
|
|
102
|
+
/** use on configResolved */
|
|
103
|
+
vite?: ResolvedConfig;
|
|
104
|
+
meta?: VixtConfigLayerMeta;
|
|
105
|
+
/** layers */
|
|
106
|
+
extends?: string[];
|
|
107
|
+
app?: AppOptions;
|
|
108
|
+
}
|
|
109
|
+
interface VixtConfigLayerMeta extends ConfigLayerMeta {
|
|
110
|
+
/** layer name */
|
|
111
|
+
name?: string;
|
|
112
|
+
/** layer alias */
|
|
113
|
+
alias?: string;
|
|
114
|
+
}
|
|
115
|
+
interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
|
|
116
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
117
|
+
cwd?: string;
|
|
118
|
+
}
|
|
119
|
+
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
120
|
+
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
|
|
121
|
+
declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
|
|
122
|
+
meta: VixtConfigLayerMeta;
|
|
123
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
124
|
+
cwd?: string;
|
|
125
|
+
config: VixtOptions | null;
|
|
126
|
+
source?: string;
|
|
127
|
+
sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
|
|
128
|
+
configFile?: string;
|
|
129
|
+
}[];
|
|
130
|
+
declare function isSamePath(a: string, b: string): boolean;
|
|
131
|
+
declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Load workspace and cwd env variables by default
|
|
135
|
+
*/
|
|
136
|
+
declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
|
|
137
|
+
/**
|
|
138
|
+
* find the workspace dir
|
|
139
|
+
*/
|
|
140
|
+
declare function findUpWorkspaceDir(): string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Load workspace env variables
|
|
143
|
+
*/
|
|
144
|
+
declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
|
|
145
|
+
|
|
146
|
+
declare const config: VixtModule<ModuleOptions>;
|
|
147
|
+
|
|
148
|
+
declare module '@vixt/core' {
|
|
149
|
+
interface VixtOptions {
|
|
150
|
+
typescript?: TypescriptOptions;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
interface TypescriptOptions {
|
|
154
|
+
references?: (string | {
|
|
155
|
+
path?: string;
|
|
156
|
+
content?: string;
|
|
157
|
+
})[];
|
|
158
|
+
tsConfig?: TSConfig & {
|
|
159
|
+
vueCompilerOptions?: RawVueCompilerOptions;
|
|
160
|
+
};
|
|
161
|
+
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
162
|
+
typeCheck?: Parameters<typeof Checker>[0];
|
|
163
|
+
/**
|
|
164
|
+
* Generate a `*.vue` shim
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
shim?: boolean;
|
|
168
|
+
}
|
|
169
|
+
declare const typescript: VixtModule<TypescriptOptions>;
|
|
170
|
+
|
|
171
|
+
declare function generateAppConfig(vixt: Vixt): string;
|
|
172
|
+
|
|
173
|
+
declare function generateClient(vixt: Vixt): void;
|
|
174
|
+
|
|
175
|
+
declare function generateCss(options: AppOptions): string;
|
|
176
|
+
|
|
177
|
+
declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
|
|
178
|
+
|
|
179
|
+
declare function generatePlugins(vixt: Vixt): string;
|
|
180
|
+
|
|
181
|
+
export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
|
|
182
|
+
export type { AppHead, AppOptions, ModuleDefinition, ModuleMeta, ModuleOptions, PluginOptions, TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as c12 from 'c12';
|
|
2
|
+
import { LoadConfigOptions, ConfigLayer, ConfigLayerMeta } from 'c12';
|
|
3
|
+
import * as vite from 'vite';
|
|
4
|
+
import { PluginOption, ResolvedConfig } from 'vite';
|
|
5
|
+
import { RawVueCompilerOptions } from '@vue/language-core';
|
|
6
|
+
import { TSConfig } from 'pkg-types';
|
|
7
|
+
import Checker from 'vite-plugin-checker';
|
|
8
|
+
|
|
9
|
+
type Property = Record<string, string>;
|
|
10
|
+
interface AppHead {
|
|
11
|
+
meta?: Property[];
|
|
12
|
+
link?: Property[];
|
|
13
|
+
style?: Property[];
|
|
14
|
+
script?: Property[];
|
|
15
|
+
title?: Property[];
|
|
16
|
+
noscript?: Property[];
|
|
17
|
+
}
|
|
18
|
+
interface AppOptions {
|
|
19
|
+
head?: AppHead;
|
|
20
|
+
/**
|
|
21
|
+
* @default /
|
|
22
|
+
*/
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
/**
|
|
25
|
+
* @default 'app'
|
|
26
|
+
*/
|
|
27
|
+
rootId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @default 'div'
|
|
30
|
+
*/
|
|
31
|
+
rootTag?: string;
|
|
32
|
+
/** inject css files */
|
|
33
|
+
css?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* @default './loading.html'
|
|
36
|
+
*/
|
|
37
|
+
loadingTemplate?: string;
|
|
38
|
+
/**
|
|
39
|
+
* @default '/src/main.ts'(vue)
|
|
40
|
+
* @default '/src/main.tsx'(react)
|
|
41
|
+
* @example 'entry.ts'(means '/src/entry.ts') or './entry.ts'
|
|
42
|
+
*/
|
|
43
|
+
entryFile?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Vixt {
|
|
47
|
+
options: VixtOptions;
|
|
48
|
+
_layers: VixtConfigLayer[];
|
|
49
|
+
_modules: VixtModule[];
|
|
50
|
+
}
|
|
51
|
+
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
52
|
+
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
53
|
+
|
|
54
|
+
type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
|
|
55
|
+
type ModuleOptions = Record<string, any>;
|
|
56
|
+
interface ModuleMeta extends Record<string, any> {
|
|
57
|
+
name?: string;
|
|
58
|
+
configKey?: string;
|
|
59
|
+
}
|
|
60
|
+
interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
|
|
61
|
+
meta?: ModuleMeta;
|
|
62
|
+
defaults?: T | ((vixt: Vixt) => T);
|
|
63
|
+
setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
|
|
64
|
+
}
|
|
65
|
+
interface VixtModule<T extends ModuleOptions = ModuleOptions> {
|
|
66
|
+
(this: void, inlineOptions: T, vixt: Vixt): PluginOption;
|
|
67
|
+
getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
|
|
68
|
+
getMeta?: () => ModuleMeta;
|
|
69
|
+
}
|
|
70
|
+
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
71
|
+
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
72
|
+
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
73
|
+
declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
|
|
74
|
+
|
|
75
|
+
interface VixtOptions extends Record<string, any> {
|
|
76
|
+
/**
|
|
77
|
+
* @default process.cwd()
|
|
78
|
+
*/
|
|
79
|
+
rootDir?: string;
|
|
80
|
+
/**
|
|
81
|
+
* @default '<rootDir>/.vixt'
|
|
82
|
+
*/
|
|
83
|
+
buildDir?: string;
|
|
84
|
+
/**
|
|
85
|
+
* @default '<buildDir>/types'
|
|
86
|
+
*/
|
|
87
|
+
buildTypesDir?: string;
|
|
88
|
+
/**
|
|
89
|
+
* @default '<buildDir>/layers'
|
|
90
|
+
*/
|
|
91
|
+
buildLayersDir?: string;
|
|
92
|
+
/**
|
|
93
|
+
* @default '<buildDir>/imports'
|
|
94
|
+
*/
|
|
95
|
+
buildImportsDir?: string;
|
|
96
|
+
/**
|
|
97
|
+
* @default '<rootDir>/src'
|
|
98
|
+
*/
|
|
99
|
+
srcDir?: string;
|
|
100
|
+
/** modules */
|
|
101
|
+
modules?: VixtModule[];
|
|
102
|
+
/** use on configResolved */
|
|
103
|
+
vite?: ResolvedConfig;
|
|
104
|
+
meta?: VixtConfigLayerMeta;
|
|
105
|
+
/** layers */
|
|
106
|
+
extends?: string[];
|
|
107
|
+
app?: AppOptions;
|
|
108
|
+
}
|
|
109
|
+
interface VixtConfigLayerMeta extends ConfigLayerMeta {
|
|
110
|
+
/** layer name */
|
|
111
|
+
name?: string;
|
|
112
|
+
/** layer alias */
|
|
113
|
+
alias?: string;
|
|
114
|
+
}
|
|
115
|
+
interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
|
|
116
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
117
|
+
cwd?: string;
|
|
118
|
+
}
|
|
119
|
+
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
120
|
+
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
|
|
121
|
+
declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
|
|
122
|
+
meta: VixtConfigLayerMeta;
|
|
123
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
124
|
+
cwd?: string;
|
|
125
|
+
config: VixtOptions | null;
|
|
126
|
+
source?: string;
|
|
127
|
+
sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
|
|
128
|
+
configFile?: string;
|
|
129
|
+
}[];
|
|
130
|
+
declare function isSamePath(a: string, b: string): boolean;
|
|
131
|
+
declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Load workspace and cwd env variables by default
|
|
135
|
+
*/
|
|
136
|
+
declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
|
|
137
|
+
/**
|
|
138
|
+
* find the workspace dir
|
|
139
|
+
*/
|
|
140
|
+
declare function findUpWorkspaceDir(): string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Load workspace env variables
|
|
143
|
+
*/
|
|
144
|
+
declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
|
|
145
|
+
|
|
146
|
+
declare const config: VixtModule<ModuleOptions>;
|
|
147
|
+
|
|
148
|
+
declare module '@vixt/core' {
|
|
149
|
+
interface VixtOptions {
|
|
150
|
+
typescript?: TypescriptOptions;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
interface TypescriptOptions {
|
|
154
|
+
references?: (string | {
|
|
155
|
+
path?: string;
|
|
156
|
+
content?: string;
|
|
157
|
+
})[];
|
|
158
|
+
tsConfig?: TSConfig & {
|
|
159
|
+
vueCompilerOptions?: RawVueCompilerOptions;
|
|
160
|
+
};
|
|
161
|
+
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
162
|
+
typeCheck?: Parameters<typeof Checker>[0];
|
|
163
|
+
/**
|
|
164
|
+
* Generate a `*.vue` shim
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
shim?: boolean;
|
|
168
|
+
}
|
|
169
|
+
declare const typescript: VixtModule<TypescriptOptions>;
|
|
170
|
+
|
|
171
|
+
declare function generateAppConfig(vixt: Vixt): string;
|
|
172
|
+
|
|
173
|
+
declare function generateClient(vixt: Vixt): void;
|
|
174
|
+
|
|
175
|
+
declare function generateCss(options: AppOptions): string;
|
|
176
|
+
|
|
177
|
+
declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
|
|
178
|
+
|
|
179
|
+
declare function generatePlugins(vixt: Vixt): string;
|
|
180
|
+
|
|
181
|
+
export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
|
|
182
|
+
export type { AppHead, AppOptions, ModuleDefinition, ModuleMeta, ModuleOptions, PluginOptions, TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions };
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { loadConfig } from 'c12';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path, { resolve, normalize } from 'pathe';
|
|
4
|
+
import { env, cwd } from 'node:process';
|
|
5
|
+
import { cac } from 'cac';
|
|
6
|
+
import { findUpSync } from 'find-up';
|
|
7
|
+
import { loadEnv as loadEnv$1 } from 'vite';
|
|
8
|
+
import defu from 'defu';
|
|
9
|
+
import { pathToFileURL } from 'mlly';
|
|
10
|
+
import 'tsx/esm';
|
|
11
|
+
import Checker from 'vite-plugin-checker';
|
|
12
|
+
|
|
13
|
+
function defineVixtConfig(input) {
|
|
14
|
+
return input;
|
|
15
|
+
}
|
|
16
|
+
async function loadVixtConfig(opts) {
|
|
17
|
+
const result = await loadConfig({
|
|
18
|
+
name: "vixt",
|
|
19
|
+
rcFile: false,
|
|
20
|
+
...opts
|
|
21
|
+
});
|
|
22
|
+
const { config, cwd } = result;
|
|
23
|
+
config.rootDir ??= cwd;
|
|
24
|
+
config.buildDir ??= resolve(config.rootDir, ".vixt");
|
|
25
|
+
config.buildTypesDir ??= resolve(config.buildDir, "types");
|
|
26
|
+
config.buildLayersDir ??= resolve(config.buildDir, "layers");
|
|
27
|
+
config.buildImportsDir ??= resolve(config.buildDir, "imports");
|
|
28
|
+
config.srcDir ??= resolve(config.rootDir, "src");
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function applyLayers(layers, config) {
|
|
32
|
+
const { rootDir, buildLayersDir } = config;
|
|
33
|
+
return layers.filter((e) => e.cwd).map((layer) => {
|
|
34
|
+
const meta = layer.config?.meta ?? {};
|
|
35
|
+
const layerName = meta.name || layer.cwd.split("/").pop();
|
|
36
|
+
if (!isSamePath(layer.cwd, resolve(rootDir))) {
|
|
37
|
+
meta.alias = `#/layers/${layerName}`;
|
|
38
|
+
}
|
|
39
|
+
if (layer.cwd?.includes("node_modules")) {
|
|
40
|
+
const newCwd = resolve(buildLayersDir, layerName);
|
|
41
|
+
fs.copySync(layer.cwd, newCwd, {
|
|
42
|
+
filter: (src) => {
|
|
43
|
+
const nodeModulesPath = resolve(layer.cwd, "node_modules");
|
|
44
|
+
const tsConfigPath = resolve(layer.cwd, "tsconfig.json");
|
|
45
|
+
return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
layer.cwd = newCwd;
|
|
49
|
+
}
|
|
50
|
+
layer.config ??= {};
|
|
51
|
+
layer.config.rootDir ??= layer.cwd;
|
|
52
|
+
layer.config.srcDir ??= resolve(layer.config.rootDir, "src");
|
|
53
|
+
return { ...layer, meta };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function isSamePath(a, b) {
|
|
57
|
+
return normalize(a) === normalize(b);
|
|
58
|
+
}
|
|
59
|
+
function resolveLayersDirs(layers = []) {
|
|
60
|
+
const dirs = {};
|
|
61
|
+
for (const layer of layers) {
|
|
62
|
+
const srcPath = layer.config.srcDir;
|
|
63
|
+
const isExist = fs.existsSync(srcPath);
|
|
64
|
+
const contents = isExist ? fs.readdirSync(srcPath) : [];
|
|
65
|
+
for (const content of contents) {
|
|
66
|
+
const fileOrDirPath = resolve(srcPath, content);
|
|
67
|
+
if (fs.statSync(fileOrDirPath).isDirectory()) {
|
|
68
|
+
dirs[content] ??= [];
|
|
69
|
+
dirs[content].push(fileOrDirPath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return dirs;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function loadEnv(mode, envDir, prefixes) {
|
|
77
|
+
const parsedArgv = cac().parse();
|
|
78
|
+
mode = mode || parsedArgv.options.mode || parsedArgv.options.m || env.NODE_ENV;
|
|
79
|
+
return {
|
|
80
|
+
MODE: mode,
|
|
81
|
+
DEV: env.NODE_ENV !== "production",
|
|
82
|
+
PROD: env.NODE_ENV === "production",
|
|
83
|
+
...loadWorkspaceEnv(mode, prefixes),
|
|
84
|
+
...loadEnv$1(mode, envDir || cwd(), prefixes)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function findUpWorkspaceDir() {
|
|
88
|
+
const workspaceManifestLocation = findUpSync(["pnpm-workspace.yaml", "pnpm-workspace.yml"]);
|
|
89
|
+
return workspaceManifestLocation && path.dirname(workspaceManifestLocation);
|
|
90
|
+
}
|
|
91
|
+
function loadWorkspaceEnv(mode, prefixes) {
|
|
92
|
+
const workspaceDir = findUpWorkspaceDir();
|
|
93
|
+
return workspaceDir ? loadEnv$1(mode, workspaceDir, prefixes) : {};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function defineVitePlugin(pluginFn) {
|
|
97
|
+
return pluginFn;
|
|
98
|
+
}
|
|
99
|
+
function defineVixtModule(definition) {
|
|
100
|
+
if (typeof definition == "function")
|
|
101
|
+
return defineVixtModule({ setup: definition });
|
|
102
|
+
const module = definition;
|
|
103
|
+
function getOptions(inlineOptions, vixt) {
|
|
104
|
+
const configKey = module.meta?.configKey || module.meta?.name;
|
|
105
|
+
const configOptions = configKey ? vixt.options[configKey] : {};
|
|
106
|
+
const defaultOptions = typeof module.defaults === "function" ? module.defaults(vixt) : module.defaults;
|
|
107
|
+
const resolvedOptions = defu(inlineOptions, configOptions, defaultOptions);
|
|
108
|
+
if (configKey) {
|
|
109
|
+
vixt.options[configKey] = resolvedOptions;
|
|
110
|
+
}
|
|
111
|
+
return resolvedOptions;
|
|
112
|
+
}
|
|
113
|
+
function normalizedModule(inlineOptions, vixt) {
|
|
114
|
+
const options = getOptions(inlineOptions, vixt);
|
|
115
|
+
return module.setup?.(options, vixt);
|
|
116
|
+
}
|
|
117
|
+
normalizedModule.getMeta = () => module.meta;
|
|
118
|
+
normalizedModule.getOptions = getOptions;
|
|
119
|
+
return normalizedModule;
|
|
120
|
+
}
|
|
121
|
+
function installModule(module, inlineOptions, vixt) {
|
|
122
|
+
return module(inlineOptions, vixt);
|
|
123
|
+
}
|
|
124
|
+
async function applyLayerModules(layers) {
|
|
125
|
+
const { modules: modulesDirs = [] } = resolveLayersDirs(layers);
|
|
126
|
+
const modules = [];
|
|
127
|
+
for (const m of modulesDirs.reverse()) {
|
|
128
|
+
if (fs.existsSync(m)) {
|
|
129
|
+
const files = fs.readdirSync(m);
|
|
130
|
+
for (const f of files) {
|
|
131
|
+
const p = path.resolve(m, f);
|
|
132
|
+
const module = await import(
|
|
133
|
+
/* @vite-ignore */
|
|
134
|
+
pathToFileURL(p)
|
|
135
|
+
).then((m2) => m2.default);
|
|
136
|
+
modules.push(module);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return modules;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const name$1 = "vixt:config";
|
|
144
|
+
const config = defineVixtModule({
|
|
145
|
+
meta: { name: name$1 },
|
|
146
|
+
setup(_, vixt) {
|
|
147
|
+
let env;
|
|
148
|
+
return {
|
|
149
|
+
name: name$1,
|
|
150
|
+
enforce: "pre",
|
|
151
|
+
config(config2) {
|
|
152
|
+
const { rootDir, buildDir, srcDir } = vixt.options;
|
|
153
|
+
const defaultAlias = {
|
|
154
|
+
"@": srcDir,
|
|
155
|
+
"~": srcDir,
|
|
156
|
+
"@@": rootDir,
|
|
157
|
+
"~~": rootDir
|
|
158
|
+
};
|
|
159
|
+
for (const layer of vixt._layers) {
|
|
160
|
+
if (layer.meta?.alias) {
|
|
161
|
+
defaultAlias[layer.meta.alias] = layer.cwd;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
defaultAlias["#"] = buildDir;
|
|
165
|
+
env = loadEnv(config2.mode, config2.envDir, config2.envPrefix);
|
|
166
|
+
const defineEnv = Object.fromEntries(
|
|
167
|
+
Object.entries(env).filter(([k]) => !["MODE", "DEV", "PROD"].includes(k)).map(([k, v]) => [`import.meta.env.${k}`, JSON.stringify(v)])
|
|
168
|
+
);
|
|
169
|
+
return {
|
|
170
|
+
root: rootDir,
|
|
171
|
+
resolve: {
|
|
172
|
+
alias: defaultAlias
|
|
173
|
+
},
|
|
174
|
+
define: defineEnv
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
configResolved(config2) {
|
|
178
|
+
Object.assign(config2.env, { ...env, ...config2.env });
|
|
179
|
+
vixt.options.vite = config2;
|
|
180
|
+
},
|
|
181
|
+
configureServer(server) {
|
|
182
|
+
const mode = server.config.mode;
|
|
183
|
+
const watchFiles = [];
|
|
184
|
+
const configFiles = vixt._layers.map((layer) => layer.configFile).filter((e) => !e.includes("node_modules"));
|
|
185
|
+
const modulesDirs = vixt._layers.map((layer) => path.resolve(layer.config.srcDir, "modules")).filter((e) => !e.includes("node_modules"));
|
|
186
|
+
watchFiles.push(...configFiles, ...modulesDirs);
|
|
187
|
+
const workspaceManifestLocation = findUpSync(["pnpm-workspace.yaml", "pnpm-workspace.yml"]);
|
|
188
|
+
if (workspaceManifestLocation) {
|
|
189
|
+
const workspaceDir = path.dirname(workspaceManifestLocation);
|
|
190
|
+
const envFiles = [`${workspaceDir}/.env`, `${workspaceDir}/.env.local`, `${workspaceDir}/.env.${mode}`, `${workspaceDir}/.env.${mode}.local`];
|
|
191
|
+
watchFiles.push(...envFiles);
|
|
192
|
+
}
|
|
193
|
+
server.watcher.add(watchFiles);
|
|
194
|
+
server.watcher.on("all", (_2, file) => {
|
|
195
|
+
const match = watchFiles.some((e) => path.normalize(file).match(e));
|
|
196
|
+
if (match)
|
|
197
|
+
server.restart();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
function generateTsConfig(options, vixt) {
|
|
205
|
+
const { buildDir } = vixt.options;
|
|
206
|
+
const codePath = path.resolve(buildDir, "tsconfig.json");
|
|
207
|
+
const code = JSON.stringify(options.tsConfig, null, 2);
|
|
208
|
+
fs.outputFileSync(codePath, code);
|
|
209
|
+
}
|
|
210
|
+
function generateVixtDts(options, vixt) {
|
|
211
|
+
const { buildDir } = vixt.options;
|
|
212
|
+
const codePath = path.resolve(buildDir, "vixt.d.ts");
|
|
213
|
+
const code = options.references?.map((reference) => {
|
|
214
|
+
if (typeof reference === "string") {
|
|
215
|
+
return `/// <reference path="${reference}" />`;
|
|
216
|
+
} else if (typeof reference === "object" && reference.path && reference.content) {
|
|
217
|
+
fs.outputFileSync(path.resolve(buildDir, reference.path), reference.content);
|
|
218
|
+
return `/// <reference path="${reference.path}" />`;
|
|
219
|
+
} else {
|
|
220
|
+
return "";
|
|
221
|
+
}
|
|
222
|
+
}).concat("export {}").join("\n");
|
|
223
|
+
if (code)
|
|
224
|
+
fs.outputFileSync(codePath, code);
|
|
225
|
+
}
|
|
226
|
+
function genarateShim(options, vixt) {
|
|
227
|
+
if (!options.shim)
|
|
228
|
+
return;
|
|
229
|
+
const { buildTypesDir } = vixt.options;
|
|
230
|
+
const code = `
|
|
231
|
+
declare module '*.vue' {
|
|
232
|
+
import type { DefineComponent } from 'vue'
|
|
233
|
+
|
|
234
|
+
const component: DefineComponent
|
|
235
|
+
export default component
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
const codePath = path.resolve(buildTypesDir, "vue-shim.d.ts");
|
|
239
|
+
fs.outputFileSync(codePath, code);
|
|
240
|
+
}
|
|
241
|
+
function generateEnvDts(env, vixt) {
|
|
242
|
+
const { buildTypesDir } = vixt.options;
|
|
243
|
+
const codePath = path.resolve(buildTypesDir, "vite-env.d.ts");
|
|
244
|
+
const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
|
|
245
|
+
${key}: ${typeof value}`).join("\n ");
|
|
246
|
+
const code = `interface ImportMeta {
|
|
247
|
+
readonly env: ImportMetaEnv
|
|
248
|
+
}
|
|
249
|
+
interface ImportMetaEnv {
|
|
250
|
+
${values}
|
|
251
|
+
}
|
|
252
|
+
`;
|
|
253
|
+
fs.outputFileSync(codePath, code);
|
|
254
|
+
}
|
|
255
|
+
const name = "vixt:typescript";
|
|
256
|
+
const typescript = defineVixtModule({
|
|
257
|
+
meta: { name, configKey: "typescript" },
|
|
258
|
+
defaults(vixt) {
|
|
259
|
+
const { rootDir, srcDir } = vixt.options;
|
|
260
|
+
const rootAlias = {};
|
|
261
|
+
if (rootDir)
|
|
262
|
+
rootAlias["@@/*"] = rootAlias["~~/*"] = [`${rootDir}/*`];
|
|
263
|
+
const srcAlias = {};
|
|
264
|
+
if (srcDir)
|
|
265
|
+
srcAlias["@/*"] = srcAlias["~/*"] = [`${srcDir}/*`];
|
|
266
|
+
const layersDirs = [];
|
|
267
|
+
const layersAlias = {};
|
|
268
|
+
for (const layer of vixt._layers) {
|
|
269
|
+
layersDirs.push(layer.cwd);
|
|
270
|
+
if (layer.meta?.alias)
|
|
271
|
+
layersAlias[`${layer.meta.alias}/*`] = [`${layer.cwd}/*`];
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
tsConfig: {
|
|
275
|
+
extends: "@vue/tsconfig/tsconfig.dom.json",
|
|
276
|
+
compilerOptions: {
|
|
277
|
+
baseUrl: rootDir,
|
|
278
|
+
paths: { "#/*": ["./*"], ...layersAlias, ...rootAlias, ...srcAlias },
|
|
279
|
+
types: ["vite/client"]
|
|
280
|
+
},
|
|
281
|
+
include: ["./**/*", ...layersDirs]
|
|
282
|
+
},
|
|
283
|
+
typeCheck: {
|
|
284
|
+
enableBuild: false,
|
|
285
|
+
overlay: { initialIsOpen: false }
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
setup(options, vixt) {
|
|
290
|
+
return [
|
|
291
|
+
{
|
|
292
|
+
name,
|
|
293
|
+
configResolved(config) {
|
|
294
|
+
generateTsConfig(options, vixt);
|
|
295
|
+
generateVixtDts(options, vixt);
|
|
296
|
+
genarateShim(options, vixt);
|
|
297
|
+
generateEnvDts(config.env, vixt);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
Checker(options.typeCheck ?? {})
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
function generateAppConfig(vixt) {
|
|
306
|
+
const { buildImportsDir } = vixt.options;
|
|
307
|
+
let appConfigsImportTemplate = "";
|
|
308
|
+
let appConfigsMergeTemplate = "";
|
|
309
|
+
let i = 0;
|
|
310
|
+
for (const layer of vixt._layers) {
|
|
311
|
+
const appConfigPath = path.resolve(layer.config.srcDir, "app.config.ts");
|
|
312
|
+
if (fs.existsSync(appConfigPath)) {
|
|
313
|
+
const appConfigName = `__app_config_${i}`;
|
|
314
|
+
appConfigsImportTemplate += `import ${appConfigName} from '${appConfigPath}'
|
|
315
|
+
`;
|
|
316
|
+
appConfigsMergeTemplate += `${appConfigName}, `;
|
|
317
|
+
i++;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const globalAppConfigKey = "__VIXT_APP_CONFIG";
|
|
321
|
+
const appConfigTemplate = `
|
|
322
|
+
import { defu } from 'defu'
|
|
323
|
+
${appConfigsImportTemplate}
|
|
324
|
+
const appConfig = defu(${appConfigsMergeTemplate}{})
|
|
325
|
+
globalThis.${globalAppConfigKey} = appConfig
|
|
326
|
+
`;
|
|
327
|
+
fs.outputFileSync(path.resolve(buildImportsDir, `app.config.ts`), `// Generated by Vixt
|
|
328
|
+
// @ts-nocheck
|
|
329
|
+
import type { VixtAppConfig } from '@vixt/core/client'
|
|
330
|
+
|
|
331
|
+
export const useAppConfig = () => globalThis.${globalAppConfigKey} as VixtAppConfig
|
|
332
|
+
`);
|
|
333
|
+
return appConfigTemplate;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function generateClient(vixt) {
|
|
337
|
+
const { buildImportsDir } = vixt.options;
|
|
338
|
+
fs.outputFileSync(
|
|
339
|
+
path.resolve(buildImportsDir, `client.ts`),
|
|
340
|
+
`// Generated by Vixt
|
|
341
|
+
export { defineAppConfig, defineVixtPlugin } from '@vixt/core/client'
|
|
342
|
+
`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function generateCss(options) {
|
|
347
|
+
const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
|
|
348
|
+
return cssTemplate;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function resolveHeadTag(tag, attrs) {
|
|
352
|
+
const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
|
|
353
|
+
return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
|
|
354
|
+
}
|
|
355
|
+
function generateIndexHtml(options, vixt) {
|
|
356
|
+
const { buildDir, rootDir, srcDir } = vixt.options;
|
|
357
|
+
const indexHtmlPath = path.resolve(rootDir, "index.html");
|
|
358
|
+
if (!fs.existsSync(indexHtmlPath))
|
|
359
|
+
fs.outputFileSync(indexHtmlPath, `<!-- Generated by Vixt -->
|
|
360
|
+
<!-- This file transform from '${path.basename(buildDir)}/index.html' -->
|
|
361
|
+
`);
|
|
362
|
+
const { head = {}, rootTag, rootId, entryFile } = options;
|
|
363
|
+
const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
364
|
+
const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
365
|
+
let { loadingTemplate = "" } = options;
|
|
366
|
+
if (!loadingTemplate) {
|
|
367
|
+
for (const layer of vixt._layers) {
|
|
368
|
+
const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
|
|
369
|
+
if (fs.existsSync(loadingTemplatePath)) {
|
|
370
|
+
loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const entryFilePath = /&\.|\//.test(entryFile ?? "") ? entryFile : `${srcDir.replace(rootDir, "")}/${entryFile}`;
|
|
376
|
+
const code = `<!DOCTYPE html>
|
|
377
|
+
<html>
|
|
378
|
+
<head>
|
|
379
|
+
${headTemplate}
|
|
380
|
+
</head>
|
|
381
|
+
<body>
|
|
382
|
+
<${rootTag} id="${rootId}">
|
|
383
|
+
${loadingTemplate}
|
|
384
|
+
</${rootTag}>
|
|
385
|
+
<script type="module" src="${entryFilePath}"><\/script>
|
|
386
|
+
${noscriptTemplate}
|
|
387
|
+
</body>
|
|
388
|
+
</html>
|
|
389
|
+
`;
|
|
390
|
+
fs.outputFileSync(path.resolve(buildDir, "index.html"), code);
|
|
391
|
+
return code;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function generatePlugins(vixt) {
|
|
395
|
+
const { plugins: pluginsDirs = [] } = resolveLayersDirs(vixt._layers);
|
|
396
|
+
let pluginsImportTemplate = "";
|
|
397
|
+
let pluginsMergeTemplate = "";
|
|
398
|
+
let i = 0;
|
|
399
|
+
for (const pluginsDir of pluginsDirs.reverse()) {
|
|
400
|
+
const files = fs.existsSync(pluginsDir) ? fs.readdirSync(pluginsDir) : [];
|
|
401
|
+
for (const f of files) {
|
|
402
|
+
const p = path.resolve(pluginsDir, f);
|
|
403
|
+
const pluginName = `__plugin_${i}`;
|
|
404
|
+
pluginsImportTemplate += `import ${pluginName} from '${p}'
|
|
405
|
+
`;
|
|
406
|
+
pluginsMergeTemplate += `${pluginName}, `;
|
|
407
|
+
i++;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const pluginsTemplate = `
|
|
411
|
+
${pluginsImportTemplate}
|
|
412
|
+
const plugins = [${pluginsMergeTemplate}]
|
|
413
|
+
function usePlugins(options) {
|
|
414
|
+
for (const plugin of plugins) {
|
|
415
|
+
typeof plugin === 'function' && plugin(options)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
`;
|
|
419
|
+
return pluginsTemplate;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async function loadVixt(opts) {
|
|
423
|
+
const result = await loadVixtConfig(defu(opts, {
|
|
424
|
+
defaults: {
|
|
425
|
+
modules: [config, typescript]
|
|
426
|
+
}
|
|
427
|
+
}));
|
|
428
|
+
const parsedArgv = cac().parse();
|
|
429
|
+
const isForce = !!parsedArgv.options.force;
|
|
430
|
+
if (isForce) {
|
|
431
|
+
fs.removeSync(result.config.buildDir);
|
|
432
|
+
}
|
|
433
|
+
result.layers = applyLayers(result.layers ?? [], result.config);
|
|
434
|
+
const layerModules = await applyLayerModules(result.layers ?? []);
|
|
435
|
+
const vixt = {
|
|
436
|
+
options: result.config,
|
|
437
|
+
_layers: result.layers ?? [],
|
|
438
|
+
_modules: [...result.config.modules ?? [], ...layerModules]
|
|
439
|
+
};
|
|
440
|
+
return vixt;
|
|
441
|
+
}
|
|
442
|
+
function createVixtPlugin(loadOptions) {
|
|
443
|
+
return defineVitePlugin(async (vixtOptions) => {
|
|
444
|
+
const vixt = await loadVixt(defu({ defaults: vixtOptions }, loadOptions));
|
|
445
|
+
const plugins = vixt._modules.map((module) => module({}, vixt));
|
|
446
|
+
return plugins;
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
|