@vizejs/vite-plugin 0.0.1-alpha.76 → 0.0.1-alpha.78
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.ts +412 -84
- package/dist/index.js +61 -19
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,406 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
2
|
|
|
3
|
+
//#region ../vize/src/types.d.ts
|
|
4
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
interface ConfigEnv {
|
|
6
|
+
mode: string;
|
|
7
|
+
command: "serve" | "build" | "check" | "lint" | "fmt";
|
|
8
|
+
isSsrBuild?: boolean;
|
|
9
|
+
}
|
|
10
|
+
type UserConfigExport = VizeConfig | ((env: ConfigEnv) => MaybePromise<VizeConfig>);
|
|
11
|
+
type RuleSeverity = "off" | "warn" | "error";
|
|
12
|
+
type RuleCategory = "correctness" | "suspicious" | "style" | "perf" | "a11y" | "security";
|
|
13
|
+
/**
|
|
14
|
+
* Vize configuration options
|
|
15
|
+
*/
|
|
16
|
+
interface VizeConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Vue compiler options
|
|
19
|
+
*/
|
|
20
|
+
compiler?: CompilerConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Vite plugin options
|
|
23
|
+
*/
|
|
24
|
+
vite?: VitePluginConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Linter options
|
|
27
|
+
*/
|
|
28
|
+
linter?: LinterConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Type checker options
|
|
31
|
+
*/
|
|
32
|
+
typeChecker?: TypeCheckerConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Formatter options
|
|
35
|
+
*/
|
|
36
|
+
formatter?: FormatterConfig;
|
|
37
|
+
/**
|
|
38
|
+
* LSP options
|
|
39
|
+
*/
|
|
40
|
+
lsp?: LspConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Musea component gallery options
|
|
43
|
+
*/
|
|
44
|
+
musea?: MuseaConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Global type declarations
|
|
47
|
+
*/
|
|
48
|
+
globalTypes?: GlobalTypesConfig;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compiler configuration
|
|
52
|
+
*/
|
|
53
|
+
interface CompilerConfig {
|
|
54
|
+
/**
|
|
55
|
+
* Compilation mode
|
|
56
|
+
* @default 'module'
|
|
57
|
+
*/
|
|
58
|
+
mode?: "module" | "function";
|
|
59
|
+
/**
|
|
60
|
+
* Enable Vapor mode compilation
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
vapor?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Enable SSR mode
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
ssr?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Enable source map generation
|
|
71
|
+
* @default true in development, false in production
|
|
72
|
+
*/
|
|
73
|
+
sourceMap?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Prefix template identifiers with _ctx
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
prefixIdentifiers?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Hoist static nodes
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
hoistStatic?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Cache v-on handlers
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
cacheHandlers?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Enable TypeScript parsing in <script> blocks
|
|
91
|
+
* @default true
|
|
92
|
+
*/
|
|
93
|
+
isTs?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Script file extension for generated output
|
|
96
|
+
* @default 'ts'
|
|
97
|
+
*/
|
|
98
|
+
scriptExt?: "ts" | "js";
|
|
99
|
+
/**
|
|
100
|
+
* Module name for runtime imports
|
|
101
|
+
* @default 'vue'
|
|
102
|
+
*/
|
|
103
|
+
runtimeModuleName?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Global variable name for runtime (IIFE builds)
|
|
106
|
+
* @default 'Vue'
|
|
107
|
+
*/
|
|
108
|
+
runtimeGlobalName?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Vite plugin configuration
|
|
112
|
+
*/
|
|
113
|
+
interface VitePluginConfig {
|
|
114
|
+
/**
|
|
115
|
+
* Files to include in compilation
|
|
116
|
+
* @default /\.vue$/
|
|
117
|
+
*/
|
|
118
|
+
include?: string | RegExp | (string | RegExp)[];
|
|
119
|
+
/**
|
|
120
|
+
* Files to exclude from compilation
|
|
121
|
+
* @default /node_modules/
|
|
122
|
+
*/
|
|
123
|
+
exclude?: string | RegExp | (string | RegExp)[];
|
|
124
|
+
/**
|
|
125
|
+
* Glob patterns to scan for .vue files during pre-compilation
|
|
126
|
+
* @default ['**\/*.vue']
|
|
127
|
+
*/
|
|
128
|
+
scanPatterns?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* Glob patterns to ignore during pre-compilation
|
|
131
|
+
* @default ['node_modules/**', 'dist/**', '.git/**']
|
|
132
|
+
*/
|
|
133
|
+
ignorePatterns?: string[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Linter configuration
|
|
137
|
+
*/
|
|
138
|
+
interface LinterConfig {
|
|
139
|
+
/**
|
|
140
|
+
* Enable linting
|
|
141
|
+
*/
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Rules to enable/disable
|
|
145
|
+
*/
|
|
146
|
+
rules?: Record<string, RuleSeverity>;
|
|
147
|
+
/**
|
|
148
|
+
* Category-level severity overrides
|
|
149
|
+
*/
|
|
150
|
+
categories?: Partial<Record<RuleCategory, RuleSeverity>>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Type checker configuration
|
|
154
|
+
*/
|
|
155
|
+
interface TypeCheckerConfig {
|
|
156
|
+
/**
|
|
157
|
+
* Enable type checking
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
enabled?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Enable strict mode
|
|
163
|
+
* @default false
|
|
164
|
+
*/
|
|
165
|
+
strict?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Check component props
|
|
168
|
+
* @default true
|
|
169
|
+
*/
|
|
170
|
+
checkProps?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Check component emits
|
|
173
|
+
* @default true
|
|
174
|
+
*/
|
|
175
|
+
checkEmits?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Check template bindings
|
|
178
|
+
* @default true
|
|
179
|
+
*/
|
|
180
|
+
checkTemplateBindings?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Path to tsconfig.json
|
|
183
|
+
* @default auto-detected
|
|
184
|
+
*/
|
|
185
|
+
tsconfig?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Path to tsgo binary
|
|
188
|
+
*/
|
|
189
|
+
tsgoPath?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Formatter configuration
|
|
193
|
+
*/
|
|
194
|
+
interface FormatterConfig {
|
|
195
|
+
/**
|
|
196
|
+
* Max line width
|
|
197
|
+
* @default 80
|
|
198
|
+
*/
|
|
199
|
+
printWidth?: number;
|
|
200
|
+
/**
|
|
201
|
+
* Indentation width
|
|
202
|
+
* @default 2
|
|
203
|
+
*/
|
|
204
|
+
tabWidth?: number;
|
|
205
|
+
/**
|
|
206
|
+
* Use tabs for indentation
|
|
207
|
+
* @default false
|
|
208
|
+
*/
|
|
209
|
+
useTabs?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Print semicolons
|
|
212
|
+
* @default true
|
|
213
|
+
*/
|
|
214
|
+
semi?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Use single quotes
|
|
217
|
+
* @default false
|
|
218
|
+
*/
|
|
219
|
+
singleQuote?: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Trailing commas
|
|
222
|
+
* @default 'all'
|
|
223
|
+
*/
|
|
224
|
+
trailingComma?: "all" | "none" | "es5";
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* LSP configuration
|
|
228
|
+
*/
|
|
229
|
+
interface LspConfig {
|
|
230
|
+
/**
|
|
231
|
+
* Enable LSP
|
|
232
|
+
* @default true
|
|
233
|
+
*/
|
|
234
|
+
enabled?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Enable diagnostics
|
|
237
|
+
* @default true
|
|
238
|
+
*/
|
|
239
|
+
diagnostics?: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Enable completions
|
|
242
|
+
* @default true
|
|
243
|
+
*/
|
|
244
|
+
completion?: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Enable hover information
|
|
247
|
+
* @default true
|
|
248
|
+
*/
|
|
249
|
+
hover?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Enable go-to-definition
|
|
252
|
+
* @default true
|
|
253
|
+
*/
|
|
254
|
+
definition?: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Enable formatting via LSP
|
|
257
|
+
* @default true
|
|
258
|
+
*/
|
|
259
|
+
formatting?: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Enable code actions
|
|
262
|
+
* @default true
|
|
263
|
+
*/
|
|
264
|
+
codeActions?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Use tsgo for type checking in LSP
|
|
267
|
+
* @default false
|
|
268
|
+
*/
|
|
269
|
+
tsgo?: boolean;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* VRT (Visual Regression Testing) configuration for Musea
|
|
273
|
+
*/
|
|
274
|
+
interface MuseaVrtConfig {
|
|
275
|
+
/**
|
|
276
|
+
* Threshold for pixel comparison (0-1)
|
|
277
|
+
* @default 0.1
|
|
278
|
+
*/
|
|
279
|
+
threshold?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Output directory for screenshots
|
|
282
|
+
* @default '__musea_snapshots__'
|
|
283
|
+
*/
|
|
284
|
+
outDir?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Viewport sizes
|
|
287
|
+
*/
|
|
288
|
+
viewports?: Array<{
|
|
289
|
+
width: number;
|
|
290
|
+
height: number;
|
|
291
|
+
name?: string;
|
|
292
|
+
}>;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* A11y configuration for Musea
|
|
296
|
+
*/
|
|
297
|
+
interface MuseaA11yConfig {
|
|
298
|
+
/**
|
|
299
|
+
* Enable a11y checking
|
|
300
|
+
* @default false
|
|
301
|
+
*/
|
|
302
|
+
enabled?: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Axe-core rules to enable/disable
|
|
305
|
+
*/
|
|
306
|
+
rules?: Record<string, boolean>;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Autogen configuration for Musea
|
|
310
|
+
*/
|
|
311
|
+
interface MuseaAutogenConfig {
|
|
312
|
+
/**
|
|
313
|
+
* Enable auto-generation of variants
|
|
314
|
+
* @default false
|
|
315
|
+
*/
|
|
316
|
+
enabled?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Max variants to generate per component
|
|
319
|
+
* @default 10
|
|
320
|
+
*/
|
|
321
|
+
maxVariants?: number;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Musea component gallery configuration
|
|
325
|
+
*/
|
|
326
|
+
interface MuseaConfig {
|
|
327
|
+
/**
|
|
328
|
+
* Glob patterns for art files
|
|
329
|
+
* @default ['**\/*.art.vue']
|
|
330
|
+
*/
|
|
331
|
+
include?: string[];
|
|
332
|
+
/**
|
|
333
|
+
* Glob patterns to exclude
|
|
334
|
+
* @default ['node_modules/**', 'dist/**']
|
|
335
|
+
*/
|
|
336
|
+
exclude?: string[];
|
|
337
|
+
/**
|
|
338
|
+
* Base path for gallery
|
|
339
|
+
* @default '/__musea__'
|
|
340
|
+
*/
|
|
341
|
+
basePath?: string;
|
|
342
|
+
/**
|
|
343
|
+
* Enable Storybook compatibility
|
|
344
|
+
* @default false
|
|
345
|
+
*/
|
|
346
|
+
storybookCompat?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Enable inline art detection in .vue files
|
|
349
|
+
* @default false
|
|
350
|
+
*/
|
|
351
|
+
inlineArt?: boolean;
|
|
352
|
+
/**
|
|
353
|
+
* VRT configuration
|
|
354
|
+
*/
|
|
355
|
+
vrt?: MuseaVrtConfig;
|
|
356
|
+
/**
|
|
357
|
+
* A11y configuration
|
|
358
|
+
*/
|
|
359
|
+
a11y?: MuseaA11yConfig;
|
|
360
|
+
/**
|
|
361
|
+
* Autogen configuration
|
|
362
|
+
*/
|
|
363
|
+
autogen?: MuseaAutogenConfig;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Global type declaration
|
|
367
|
+
*/
|
|
368
|
+
interface GlobalTypeDeclaration {
|
|
369
|
+
/**
|
|
370
|
+
* TypeScript type string
|
|
371
|
+
*/
|
|
372
|
+
type: string;
|
|
373
|
+
/**
|
|
374
|
+
* Default value
|
|
375
|
+
*/
|
|
376
|
+
defaultValue?: string;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Global types configuration
|
|
380
|
+
*/
|
|
381
|
+
type GlobalTypesConfig = Record<string, GlobalTypeDeclaration | string>;
|
|
382
|
+
/**
|
|
383
|
+
* Options for loading vize.config file
|
|
384
|
+
*/
|
|
385
|
+
interface LoadConfigOptions {
|
|
386
|
+
/**
|
|
387
|
+
* Config file search mode
|
|
388
|
+
* - 'root': Search only in the specified root directory
|
|
389
|
+
* - 'auto': Search from cwd upward until finding a config file
|
|
390
|
+
* - 'none': Don't load config file
|
|
391
|
+
* @default 'root'
|
|
392
|
+
*/
|
|
393
|
+
mode?: "root" | "auto" | "none";
|
|
394
|
+
/**
|
|
395
|
+
* Custom config file path (overrides automatic search)
|
|
396
|
+
*/
|
|
397
|
+
configFile?: string;
|
|
398
|
+
/**
|
|
399
|
+
* Config environment for dynamic config resolution
|
|
400
|
+
*/
|
|
401
|
+
env?: ConfigEnv;
|
|
402
|
+
} //#endregion
|
|
3
403
|
//#region src/types.d.ts
|
|
4
|
-
|
|
5
404
|
interface VizeOptions {
|
|
6
405
|
/**
|
|
7
406
|
* Files to include in compilation
|
|
@@ -75,96 +474,25 @@ interface CompiledModule {
|
|
|
75
474
|
styleHash?: string;
|
|
76
475
|
scriptHash?: string;
|
|
77
476
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*/
|
|
81
|
-
interface VizeConfig {
|
|
82
|
-
/**
|
|
83
|
-
* Vue compiler options
|
|
84
|
-
*/
|
|
85
|
-
compiler?: {
|
|
86
|
-
/**
|
|
87
|
-
* Enable Vapor mode compilation
|
|
88
|
-
* @default false
|
|
89
|
-
*/
|
|
90
|
-
vapor?: boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Enable SSR mode
|
|
93
|
-
* @default false
|
|
94
|
-
*/
|
|
95
|
-
ssr?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Enable source map generation
|
|
98
|
-
* @default true in development, false in production
|
|
99
|
-
*/
|
|
100
|
-
sourceMap?: boolean;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Vite plugin options
|
|
104
|
-
*/
|
|
105
|
-
vite?: {
|
|
106
|
-
/**
|
|
107
|
-
* Files to include in compilation
|
|
108
|
-
* @default /\.vue$/
|
|
109
|
-
*/
|
|
110
|
-
include?: string | RegExp | (string | RegExp)[];
|
|
111
|
-
/**
|
|
112
|
-
* Files to exclude from compilation
|
|
113
|
-
* @default /node_modules/
|
|
114
|
-
*/
|
|
115
|
-
exclude?: string | RegExp | (string | RegExp)[];
|
|
116
|
-
/**
|
|
117
|
-
* Glob patterns to scan for .vue files during pre-compilation
|
|
118
|
-
* @default ['**\/*.vue']
|
|
119
|
-
*/
|
|
120
|
-
scanPatterns?: string[];
|
|
121
|
-
/**
|
|
122
|
-
* Glob patterns to ignore during pre-compilation
|
|
123
|
-
* @default ['node_modules/**', 'dist/**', '.git/**']
|
|
124
|
-
*/
|
|
125
|
-
ignorePatterns?: string[];
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Linter options
|
|
129
|
-
*/
|
|
130
|
-
linter?: {
|
|
131
|
-
/**
|
|
132
|
-
* Enable linting
|
|
133
|
-
*/
|
|
134
|
-
enabled?: boolean;
|
|
135
|
-
/**
|
|
136
|
-
* Rules to enable/disable
|
|
137
|
-
*/
|
|
138
|
-
rules?: Record<string, "off" | "warn" | "error">;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Options for loading vize.config file
|
|
143
|
-
*/
|
|
144
|
-
interface LoadConfigOptions {
|
|
145
|
-
/**
|
|
146
|
-
* Config file search mode
|
|
147
|
-
* - 'root': Search only in the specified root directory
|
|
148
|
-
* - 'auto': Search from cwd upward until finding a config file
|
|
149
|
-
* - 'none': Don't load config file
|
|
150
|
-
* @default 'root'
|
|
151
|
-
*/
|
|
152
|
-
mode?: "root" | "auto" | "none";
|
|
153
|
-
/**
|
|
154
|
-
* Custom config file path (overrides automatic search)
|
|
155
|
-
*/
|
|
156
|
-
configFile?: string;
|
|
157
|
-
} //#endregion
|
|
477
|
+
|
|
478
|
+
//#endregion
|
|
158
479
|
//#region src/index.d.ts
|
|
159
480
|
/**
|
|
160
|
-
* Define a Vize configuration with type checking
|
|
481
|
+
* Define a Vize configuration with type checking.
|
|
482
|
+
* Accepts a plain object or a function that receives ConfigEnv.
|
|
161
483
|
*/
|
|
162
|
-
declare function defineConfig(config:
|
|
484
|
+
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
163
485
|
/**
|
|
164
486
|
* Load Vize configuration from file
|
|
165
487
|
*/
|
|
166
488
|
declare function loadConfig(root: string, options?: LoadConfigOptions): Promise<VizeConfig | null>;
|
|
489
|
+
/**
|
|
490
|
+
* Shared config store for inter-plugin communication.
|
|
491
|
+
* Key = project root, Value = resolved VizeConfig.
|
|
492
|
+
* Used by musea() and other plugins to access the unified config.
|
|
493
|
+
*/
|
|
494
|
+
declare const vizeConfigStore: Map<string, VizeConfig>;
|
|
167
495
|
declare function vize(options?: VizeOptions): Plugin;
|
|
168
496
|
|
|
169
497
|
//#endregion
|
|
170
|
-
export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, vize as default, defineConfig, loadConfig, vize };
|
|
498
|
+
export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, vize as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transformWithOxc } from "vite";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import { glob } from "tinyglobby";
|
|
@@ -179,11 +180,15 @@ const CONFIG_FILES = [
|
|
|
179
180
|
"vize.config.ts",
|
|
180
181
|
"vize.config.js",
|
|
181
182
|
"vize.config.mjs",
|
|
182
|
-
"vize.config.cjs",
|
|
183
183
|
"vize.config.json"
|
|
184
184
|
];
|
|
185
|
+
const DEFAULT_CONFIG_ENV = {
|
|
186
|
+
mode: "development",
|
|
187
|
+
command: "serve"
|
|
188
|
+
};
|
|
185
189
|
/**
|
|
186
|
-
* Define a Vize configuration with type checking
|
|
190
|
+
* Define a Vize configuration with type checking.
|
|
191
|
+
* Accepts a plain object or a function that receives ConfigEnv.
|
|
187
192
|
*/
|
|
188
193
|
function defineConfig(config) {
|
|
189
194
|
return config;
|
|
@@ -192,27 +197,38 @@ function defineConfig(config) {
|
|
|
192
197
|
* Load Vize configuration from file
|
|
193
198
|
*/
|
|
194
199
|
async function loadConfig(root, options = {}) {
|
|
195
|
-
const { mode = "root", configFile } = options;
|
|
200
|
+
const { mode = "root", configFile, env } = options;
|
|
196
201
|
if (mode === "none") return null;
|
|
197
|
-
const searchMode = mode === "auto" ? "nearest" : mode;
|
|
198
202
|
if (configFile) {
|
|
199
203
|
const configPath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
|
|
200
|
-
return loadConfigFile(configPath);
|
|
204
|
+
return loadConfigFile(configPath, env);
|
|
201
205
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
206
|
+
if (mode === "auto") {
|
|
207
|
+
let searchDir = root;
|
|
208
|
+
while (true) {
|
|
209
|
+
const found$1 = findConfigInDir(searchDir);
|
|
210
|
+
if (found$1) return loadConfigFile(found$1, env);
|
|
211
|
+
const parentDir = path.dirname(searchDir);
|
|
212
|
+
if (parentDir === searchDir) break;
|
|
213
|
+
searchDir = parentDir;
|
|
207
214
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const found = findConfigInDir(root);
|
|
218
|
+
return found ? loadConfigFile(found, env) : null;
|
|
219
|
+
}
|
|
220
|
+
function findConfigInDir(dir) {
|
|
221
|
+
for (const filename of CONFIG_FILES) {
|
|
222
|
+
const configPath = path.join(dir, filename);
|
|
223
|
+
if (fs.existsSync(configPath)) return configPath;
|
|
212
224
|
}
|
|
213
225
|
return null;
|
|
214
226
|
}
|
|
215
|
-
async function
|
|
227
|
+
async function resolveConfigExport(exported, env) {
|
|
228
|
+
if (typeof exported === "function") return exported(env ?? DEFAULT_CONFIG_ENV);
|
|
229
|
+
return exported;
|
|
230
|
+
}
|
|
231
|
+
async function loadConfigFile(configPath, env) {
|
|
216
232
|
if (!fs.existsSync(configPath)) return null;
|
|
217
233
|
const ext = path.extname(configPath);
|
|
218
234
|
if (ext === ".json") {
|
|
@@ -221,12 +237,19 @@ async function loadConfigFile(configPath) {
|
|
|
221
237
|
}
|
|
222
238
|
try {
|
|
223
239
|
const module = await import(configPath);
|
|
224
|
-
|
|
240
|
+
const exported = module.default ?? module;
|
|
241
|
+
return resolveConfigExport(exported, env);
|
|
225
242
|
} catch (e) {
|
|
226
243
|
console.warn(`[vize] Failed to load config from ${configPath}:`, e);
|
|
227
244
|
return null;
|
|
228
245
|
}
|
|
229
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Shared config store for inter-plugin communication.
|
|
249
|
+
* Key = project root, Value = resolved VizeConfig.
|
|
250
|
+
* Used by musea() and other plugins to access the unified config.
|
|
251
|
+
*/
|
|
252
|
+
const vizeConfigStore = new Map();
|
|
230
253
|
const VIRTUAL_PREFIX = "\0vize:";
|
|
231
254
|
const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
|
|
232
255
|
const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
|
|
@@ -312,13 +335,22 @@ function vize(options = {}) {
|
|
|
312
335
|
root = options.root ?? resolvedConfig.root;
|
|
313
336
|
isProduction = options.isProduction ?? resolvedConfig.isProduction;
|
|
314
337
|
extractCss = isProduction;
|
|
338
|
+
const configEnv = {
|
|
339
|
+
mode: resolvedConfig.mode,
|
|
340
|
+
command: resolvedConfig.command === "build" ? "build" : "serve",
|
|
341
|
+
isSsrBuild: !!resolvedConfig.build?.ssr
|
|
342
|
+
};
|
|
315
343
|
let fileConfig = null;
|
|
316
344
|
if (options.configMode !== false) {
|
|
317
345
|
fileConfig = await loadConfig(root, {
|
|
318
346
|
mode: options.configMode ?? "root",
|
|
319
|
-
configFile: options.configFile
|
|
347
|
+
configFile: options.configFile,
|
|
348
|
+
env: configEnv
|
|
320
349
|
});
|
|
321
|
-
if (fileConfig)
|
|
350
|
+
if (fileConfig) {
|
|
351
|
+
logger.log("Loaded config from vize.config file");
|
|
352
|
+
vizeConfigStore.set(root, fileConfig);
|
|
353
|
+
}
|
|
322
354
|
}
|
|
323
355
|
const viteConfig = fileConfig?.vite ?? {};
|
|
324
356
|
const compilerConfig = fileConfig?.compiler ?? {};
|
|
@@ -444,6 +476,16 @@ function vize(options = {}) {
|
|
|
444
476
|
}
|
|
445
477
|
return null;
|
|
446
478
|
},
|
|
479
|
+
async transform(code, id) {
|
|
480
|
+
if (id.startsWith(VIRTUAL_PREFIX) && id.endsWith(".ts")) {
|
|
481
|
+
const result = await transformWithOxc(code, id.slice(VIRTUAL_PREFIX.length), { lang: "ts" });
|
|
482
|
+
return {
|
|
483
|
+
code: result.code,
|
|
484
|
+
map: result.map
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
return null;
|
|
488
|
+
},
|
|
447
489
|
async handleHotUpdate(ctx) {
|
|
448
490
|
const { file, server: server$1, read } = ctx;
|
|
449
491
|
if (file.endsWith(".vue") && filter(file)) try {
|
|
@@ -492,4 +534,4 @@ function vize(options = {}) {
|
|
|
492
534
|
var src_default = vize;
|
|
493
535
|
|
|
494
536
|
//#endregion
|
|
495
|
-
export { src_default as default, defineConfig, loadConfig, vize };
|
|
537
|
+
export { src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.78",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"provenance": true,
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"tinyglobby": "^0.2.0",
|
|
47
|
-
"@vizejs/native": "0.0.1-alpha.
|
|
47
|
+
"@vizejs/native": "0.0.1-alpha.78"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsdown",
|