@vizejs/vite-plugin 0.0.1-alpha.8 → 0.0.1-alpha.81
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/README.md +5 -5
- package/dist/index.d.ts +498 -5
- package/dist/index.js +534 -138
- package/package.json +23 -13
- package/dist/compiler.d.ts +0 -6
- package/dist/compiler.js +0 -46
- package/dist/types.d.ts +0 -66
- package/dist/types.js +0 -1
- package/dist/utils.d.ts +0 -4
- package/dist/utils.js +0 -71
package/dist/index.js
CHANGED
|
@@ -1,141 +1,537 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
import { transformWithOxc } from "vite";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { glob } from "tinyglobby";
|
|
5
|
+
import * as native from "@vizejs/native";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
|
|
8
|
+
//#region src/hmr.ts
|
|
9
|
+
/**
|
|
10
|
+
* Detect the type of HMR update needed based on content hash changes.
|
|
11
|
+
*
|
|
12
|
+
* @param prev - Previously compiled module (undefined if first compile)
|
|
13
|
+
* @param next - Newly compiled module
|
|
14
|
+
* @returns The type of HMR update needed
|
|
15
|
+
*/
|
|
16
|
+
function detectHmrUpdateType(prev, next) {
|
|
17
|
+
if (!prev) return "full-reload";
|
|
18
|
+
const scriptChanged = prev.scriptHash !== next.scriptHash;
|
|
19
|
+
if (scriptChanged) return "full-reload";
|
|
20
|
+
const templateChanged = prev.templateHash !== next.templateHash;
|
|
21
|
+
const styleChanged = prev.styleHash !== next.styleHash;
|
|
22
|
+
if (styleChanged && !templateChanged) return "style-only";
|
|
23
|
+
if (templateChanged) return "template-only";
|
|
24
|
+
return "full-reload";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate HMR-aware code output based on update type.
|
|
28
|
+
*/
|
|
29
|
+
function generateHmrCode(scopeId, updateType) {
|
|
30
|
+
return `
|
|
31
|
+
if (import.meta.hot) {
|
|
32
|
+
_sfc_main.__hmrId = ${JSON.stringify(scopeId)};
|
|
33
|
+
_sfc_main.__hmrUpdateType = ${JSON.stringify(updateType)};
|
|
34
|
+
|
|
35
|
+
import.meta.hot.accept((mod) => {
|
|
36
|
+
if (!mod) return;
|
|
37
|
+
const { default: updated } = mod;
|
|
38
|
+
if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
|
|
39
|
+
const updateType = updated.__hmrUpdateType || 'full-reload';
|
|
40
|
+
if (updateType === 'template-only') {
|
|
41
|
+
__VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render);
|
|
42
|
+
} else {
|
|
43
|
+
__VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated);
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
else {
|
|
59
|
-
resolved = path.resolve(root, id);
|
|
60
|
-
}
|
|
61
|
-
return path.normalize(resolved);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
import.meta.hot.on('vize:update', (data) => {
|
|
49
|
+
if (data.id !== _sfc_main.__hmrId) return;
|
|
50
|
+
|
|
51
|
+
if (data.type === 'style-only') {
|
|
52
|
+
// Update styles without remounting component
|
|
53
|
+
const styleId = 'vize-style-' + _sfc_main.__hmrId;
|
|
54
|
+
const styleEl = document.getElementById(styleId);
|
|
55
|
+
if (styleEl && data.css) {
|
|
56
|
+
styleEl.textContent = data.css;
|
|
57
|
+
}
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
|
|
62
|
+
__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main);
|
|
63
|
+
}
|
|
64
|
+
}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/utils.ts
|
|
69
|
+
function generateScopeId(filename) {
|
|
70
|
+
const hash = createHash("sha256").update(filename).digest("hex");
|
|
71
|
+
return hash.slice(0, 8);
|
|
72
|
+
}
|
|
73
|
+
function createFilter(include, exclude) {
|
|
74
|
+
const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/];
|
|
75
|
+
const excludePatterns = exclude ? Array.isArray(exclude) ? exclude : [exclude] : [/node_modules/];
|
|
76
|
+
return (id) => {
|
|
77
|
+
const matchInclude = includePatterns.some((pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id));
|
|
78
|
+
const matchExclude = excludePatterns.some((pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id));
|
|
79
|
+
return matchInclude && !matchExclude;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function generateOutput(compiled, options) {
|
|
83
|
+
const { isProduction, isDev, hmrUpdateType, extractCss } = options;
|
|
84
|
+
let output = compiled.code;
|
|
85
|
+
const exportDefaultRegex = /^export default /m;
|
|
86
|
+
const hasExportDefault = exportDefaultRegex.test(output);
|
|
87
|
+
const hasSfcMainDefined = /\bconst\s+_sfc_main\s*=/.test(output);
|
|
88
|
+
if (hasExportDefault && !hasSfcMainDefined) {
|
|
89
|
+
output = output.replace(exportDefaultRegex, "const _sfc_main = ");
|
|
90
|
+
if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
|
|
91
|
+
output += "\nexport default _sfc_main;";
|
|
92
|
+
} else if (hasExportDefault && hasSfcMainDefined) {
|
|
93
|
+
if (compiled.hasScoped && compiled.scopeId) output = output.replace(/^export default _sfc_main/m, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";\nexport default _sfc_main`);
|
|
94
|
+
}
|
|
95
|
+
if (compiled.css && !(isProduction && extractCss)) {
|
|
96
|
+
const cssCode = JSON.stringify(compiled.css);
|
|
97
|
+
const cssId = JSON.stringify(`vize-style-${compiled.scopeId}`);
|
|
98
|
+
output = `
|
|
99
|
+
const __vize_css__ = ${cssCode};
|
|
100
|
+
const __vize_css_id__ = ${cssId};
|
|
101
|
+
(function() {
|
|
102
|
+
if (typeof document !== 'undefined') {
|
|
103
|
+
let style = document.getElementById(__vize_css_id__);
|
|
104
|
+
if (!style) {
|
|
105
|
+
style = document.createElement('style');
|
|
106
|
+
style.id = __vize_css_id__;
|
|
107
|
+
style.textContent = __vize_css__;
|
|
108
|
+
document.head.appendChild(style);
|
|
109
|
+
} else {
|
|
110
|
+
style.textContent = __vize_css__;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
${output}`;
|
|
115
|
+
}
|
|
116
|
+
if (!isProduction && isDev && hasExportDefault) output += generateHmrCode(compiled.scopeId, hmrUpdateType ?? "full-reload");
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/compiler.ts
|
|
122
|
+
const { compileSfc, compileSfcBatchWithResults } = native;
|
|
123
|
+
function compileFile(filePath, cache, options, source) {
|
|
124
|
+
const content = source ?? fs.readFileSync(filePath, "utf-8");
|
|
125
|
+
const scopeId = generateScopeId(filePath);
|
|
126
|
+
const hasScoped = /<style[^>]*\bscoped\b/.test(content);
|
|
127
|
+
const result = compileSfc(content, {
|
|
128
|
+
filename: filePath,
|
|
129
|
+
sourceMap: options.sourceMap,
|
|
130
|
+
ssr: options.ssr,
|
|
131
|
+
scopeId: hasScoped ? `data-v-${scopeId}` : void 0
|
|
132
|
+
});
|
|
133
|
+
if (result.errors.length > 0) {
|
|
134
|
+
const errorMsg = result.errors.join("\n");
|
|
135
|
+
console.error(`[vize] Compilation error in ${filePath}:\n${errorMsg}`);
|
|
136
|
+
}
|
|
137
|
+
if (result.warnings.length > 0) result.warnings.forEach((warning) => {
|
|
138
|
+
console.warn(`[vize] Warning in ${filePath}: ${warning}`);
|
|
139
|
+
});
|
|
140
|
+
const compiled = {
|
|
141
|
+
code: result.code,
|
|
142
|
+
css: result.css,
|
|
143
|
+
scopeId,
|
|
144
|
+
hasScoped
|
|
145
|
+
};
|
|
146
|
+
cache.set(filePath, compiled);
|
|
147
|
+
return compiled;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Batch compile multiple files in parallel using native Rust multithreading.
|
|
151
|
+
* Returns per-file results with content hashes for HMR.
|
|
152
|
+
*/
|
|
153
|
+
function compileBatch(files, cache, options) {
|
|
154
|
+
const inputs = files.map((f) => ({
|
|
155
|
+
path: f.path,
|
|
156
|
+
source: f.source
|
|
157
|
+
}));
|
|
158
|
+
const result = compileSfcBatchWithResults(inputs, { ssr: options.ssr });
|
|
159
|
+
for (const fileResult of result.results) {
|
|
160
|
+
if (fileResult.errors.length === 0) cache.set(fileResult.path, {
|
|
161
|
+
code: fileResult.code,
|
|
162
|
+
css: fileResult.css,
|
|
163
|
+
scopeId: fileResult.scopeId,
|
|
164
|
+
hasScoped: fileResult.hasScoped,
|
|
165
|
+
templateHash: fileResult.templateHash,
|
|
166
|
+
styleHash: fileResult.styleHash,
|
|
167
|
+
scriptHash: fileResult.scriptHash
|
|
168
|
+
});
|
|
169
|
+
if (fileResult.errors.length > 0) console.error(`[vize] Compilation error in ${fileResult.path}:\n${fileResult.errors.join("\n")}`);
|
|
170
|
+
if (fileResult.warnings.length > 0) fileResult.warnings.forEach((warning) => {
|
|
171
|
+
console.warn(`[vize] Warning in ${fileResult.path}: ${warning}`);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/index.ts
|
|
179
|
+
const CONFIG_FILES = [
|
|
180
|
+
"vize.config.ts",
|
|
181
|
+
"vize.config.js",
|
|
182
|
+
"vize.config.mjs",
|
|
183
|
+
"vize.config.json"
|
|
184
|
+
];
|
|
185
|
+
const DEFAULT_CONFIG_ENV = {
|
|
186
|
+
mode: "development",
|
|
187
|
+
command: "serve"
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Define a Vize configuration with type checking.
|
|
191
|
+
* Accepts a plain object or a function that receives ConfigEnv.
|
|
192
|
+
*/
|
|
193
|
+
function defineConfig(config) {
|
|
194
|
+
return config;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Load Vize configuration from file
|
|
198
|
+
*/
|
|
199
|
+
async function loadConfig(root, options = {}) {
|
|
200
|
+
const { mode = "root", configFile, env } = options;
|
|
201
|
+
if (mode === "none") return null;
|
|
202
|
+
if (configFile) {
|
|
203
|
+
const configPath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
|
|
204
|
+
return loadConfigFile(configPath, env);
|
|
205
|
+
}
|
|
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;
|
|
214
|
+
}
|
|
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;
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
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) {
|
|
232
|
+
if (!fs.existsSync(configPath)) return null;
|
|
233
|
+
const ext = path.extname(configPath);
|
|
234
|
+
if (ext === ".json") {
|
|
235
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
236
|
+
return JSON.parse(content);
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
const module = await import(configPath);
|
|
240
|
+
const exported = module.default ?? module;
|
|
241
|
+
return resolveConfigExport(exported, env);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
console.warn(`[vize] Failed to load config from ${configPath}:`, e);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
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();
|
|
253
|
+
const VIRTUAL_PREFIX = "\0vize:";
|
|
254
|
+
const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
|
|
255
|
+
const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
|
|
256
|
+
function createLogger(debug) {
|
|
257
|
+
return {
|
|
258
|
+
log: (...args) => debug && console.log("[vize]", ...args),
|
|
259
|
+
info: (...args) => console.log("[vize]", ...args),
|
|
260
|
+
warn: (...args) => console.warn("[vize]", ...args),
|
|
261
|
+
error: (...args) => console.error("[vize]", ...args)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function vize(options = {}) {
|
|
265
|
+
const cache = new Map();
|
|
266
|
+
const virtualToReal = new Map();
|
|
267
|
+
const collectedCss = new Map();
|
|
268
|
+
let isProduction;
|
|
269
|
+
let root;
|
|
270
|
+
let server = null;
|
|
271
|
+
let filter;
|
|
272
|
+
let scanPatterns;
|
|
273
|
+
let ignorePatterns;
|
|
274
|
+
let mergedOptions;
|
|
275
|
+
let extractCss = false;
|
|
276
|
+
const logger = createLogger(options.debug ?? false);
|
|
277
|
+
async function compileAll() {
|
|
278
|
+
const startTime = performance.now();
|
|
279
|
+
const files = await glob(scanPatterns, {
|
|
280
|
+
cwd: root,
|
|
281
|
+
ignore: ignorePatterns,
|
|
282
|
+
absolute: true
|
|
283
|
+
});
|
|
284
|
+
logger.info(`Pre-compiling ${files.length} Vue files...`);
|
|
285
|
+
const fileContents = [];
|
|
286
|
+
for (const file of files) try {
|
|
287
|
+
const source = fs.readFileSync(file, "utf-8");
|
|
288
|
+
fileContents.push({
|
|
289
|
+
path: file,
|
|
290
|
+
source
|
|
291
|
+
});
|
|
292
|
+
} catch (e) {
|
|
293
|
+
logger.error(`Failed to read ${file}:`, e);
|
|
294
|
+
}
|
|
295
|
+
const result = compileBatch(fileContents, cache, { ssr: mergedOptions.ssr ?? false });
|
|
296
|
+
if (isProduction) {
|
|
297
|
+
for (const fileResult of result.results) if (fileResult.css) collectedCss.set(fileResult.path, fileResult.css);
|
|
298
|
+
}
|
|
299
|
+
const elapsed = (performance.now() - startTime).toFixed(2);
|
|
300
|
+
logger.info(`Pre-compilation complete: ${result.successCount} succeeded, ${result.failedCount} failed (${elapsed}ms, native batch: ${result.timeMs.toFixed(2)}ms)`);
|
|
301
|
+
}
|
|
302
|
+
function resolveVuePath(id, importer) {
|
|
303
|
+
let resolved;
|
|
304
|
+
if (id.startsWith("/@fs/")) resolved = id.slice(4);
|
|
305
|
+
else if (id.startsWith("/") && !fs.existsSync(id)) resolved = path.resolve(root, id.slice(1));
|
|
306
|
+
else if (path.isAbsolute(id)) resolved = id;
|
|
307
|
+
else if (importer) {
|
|
308
|
+
let realImporter = importer.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length) : importer;
|
|
309
|
+
if (realImporter.endsWith(".vue.ts")) realImporter = realImporter.slice(0, -3);
|
|
310
|
+
resolved = path.resolve(path.dirname(realImporter), id);
|
|
311
|
+
} else resolved = path.resolve(root, id);
|
|
312
|
+
if (!path.isAbsolute(resolved)) resolved = path.resolve(root, resolved);
|
|
313
|
+
return path.normalize(resolved);
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
name: "vite-plugin-vize",
|
|
317
|
+
enforce: "pre",
|
|
318
|
+
config() {
|
|
319
|
+
return { optimizeDeps: {
|
|
320
|
+
include: ["vue"],
|
|
321
|
+
exclude: ["virtual:vize-styles"],
|
|
322
|
+
esbuildOptions: { plugins: [{
|
|
323
|
+
name: "vize-externalize-vue",
|
|
324
|
+
setup(build) {
|
|
325
|
+
build.onResolve({ filter: /\.vue$/ }, (args) => ({
|
|
326
|
+
path: args.path,
|
|
327
|
+
external: true
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
}] },
|
|
331
|
+
rolldownOptions: { external: [/\.vue$/] }
|
|
332
|
+
} };
|
|
333
|
+
},
|
|
334
|
+
async configResolved(resolvedConfig) {
|
|
335
|
+
root = options.root ?? resolvedConfig.root;
|
|
336
|
+
isProduction = options.isProduction ?? resolvedConfig.isProduction;
|
|
337
|
+
extractCss = isProduction;
|
|
338
|
+
const configEnv = {
|
|
339
|
+
mode: resolvedConfig.mode,
|
|
340
|
+
command: resolvedConfig.command === "build" ? "build" : "serve",
|
|
341
|
+
isSsrBuild: !!resolvedConfig.build?.ssr
|
|
342
|
+
};
|
|
343
|
+
let fileConfig = null;
|
|
344
|
+
if (options.configMode !== false) {
|
|
345
|
+
fileConfig = await loadConfig(root, {
|
|
346
|
+
mode: options.configMode ?? "root",
|
|
347
|
+
configFile: options.configFile,
|
|
348
|
+
env: configEnv
|
|
349
|
+
});
|
|
350
|
+
if (fileConfig) {
|
|
351
|
+
logger.log("Loaded config from vize.config file");
|
|
352
|
+
vizeConfigStore.set(root, fileConfig);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const viteConfig = fileConfig?.vite ?? {};
|
|
356
|
+
const compilerConfig = fileConfig?.compiler ?? {};
|
|
357
|
+
mergedOptions = {
|
|
358
|
+
...options,
|
|
359
|
+
ssr: options.ssr ?? compilerConfig.ssr ?? false,
|
|
360
|
+
sourceMap: options.sourceMap ?? compilerConfig.sourceMap,
|
|
361
|
+
vapor: options.vapor ?? compilerConfig.vapor ?? false,
|
|
362
|
+
include: options.include ?? viteConfig.include,
|
|
363
|
+
exclude: options.exclude ?? viteConfig.exclude,
|
|
364
|
+
scanPatterns: options.scanPatterns ?? viteConfig.scanPatterns,
|
|
365
|
+
ignorePatterns: options.ignorePatterns ?? viteConfig.ignorePatterns
|
|
366
|
+
};
|
|
367
|
+
filter = createFilter(mergedOptions.include, mergedOptions.exclude);
|
|
368
|
+
scanPatterns = mergedOptions.scanPatterns ?? ["**/*.vue"];
|
|
369
|
+
ignorePatterns = mergedOptions.ignorePatterns ?? [
|
|
370
|
+
"node_modules/**",
|
|
371
|
+
"dist/**",
|
|
372
|
+
".git/**"
|
|
373
|
+
];
|
|
374
|
+
},
|
|
375
|
+
configureServer(devServer) {
|
|
376
|
+
server = devServer;
|
|
377
|
+
},
|
|
378
|
+
async buildStart() {
|
|
379
|
+
await compileAll();
|
|
380
|
+
logger.log("Cache keys:", [...cache.keys()].slice(0, 3));
|
|
381
|
+
},
|
|
382
|
+
async resolveId(id, importer) {
|
|
383
|
+
if (id.startsWith("\0")) return null;
|
|
384
|
+
if (id.startsWith("vize:")) {
|
|
385
|
+
let realPath = id.slice(5);
|
|
386
|
+
if (realPath.endsWith(".ts")) realPath = realPath.slice(0, -3);
|
|
387
|
+
logger.log(`resolveId: redirecting stale vize: ID to ${realPath}`);
|
|
388
|
+
if (realPath.includes("node_modules")) return realPath;
|
|
389
|
+
return this.resolve(realPath, importer, { skipSelf: true });
|
|
390
|
+
}
|
|
391
|
+
if (id === VIRTUAL_CSS_MODULE) return RESOLVED_CSS_MODULE;
|
|
392
|
+
if (id.includes("?vue&type=style")) return id;
|
|
393
|
+
if (importer?.startsWith(VIRTUAL_PREFIX)) {
|
|
394
|
+
const realImporter = virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length);
|
|
395
|
+
const cleanImporter = realImporter.endsWith(".ts") ? realImporter.slice(0, -3) : realImporter;
|
|
396
|
+
logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
397
|
+
if (!id.endsWith(".vue")) if (id.startsWith("./") || id.startsWith("../")) {
|
|
398
|
+
const [pathPart, queryPart] = id.split("?");
|
|
399
|
+
const querySuffix = queryPart ? `?${queryPart}` : "";
|
|
400
|
+
const resolved = path.resolve(path.dirname(cleanImporter), pathPart);
|
|
401
|
+
for (const ext of [
|
|
402
|
+
"",
|
|
403
|
+
".ts",
|
|
404
|
+
".tsx",
|
|
405
|
+
".js",
|
|
406
|
+
".jsx",
|
|
407
|
+
".json"
|
|
408
|
+
]) if (fs.existsSync(resolved + ext)) {
|
|
409
|
+
const finalPath = resolved + ext + querySuffix;
|
|
410
|
+
logger.log(`resolveId: resolved relative ${id} to ${finalPath}`);
|
|
411
|
+
return finalPath;
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
if (id.includes("/dist/") || id.includes("/lib/") || id.includes("/es/")) {
|
|
415
|
+
logger.log(`resolveId: skipping already-resolved path ${id}`);
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
logger.log(`resolveId: resolving external ${id} from ${cleanImporter}`);
|
|
419
|
+
const resolved = await this.resolve(id, cleanImporter, { skipSelf: true });
|
|
420
|
+
logger.log(`resolveId: resolved external ${id} to`, resolved?.id ?? "null");
|
|
421
|
+
return resolved;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (id.endsWith(".vue")) {
|
|
425
|
+
if (id.includes("node_modules")) {
|
|
426
|
+
logger.log(`resolveId: skipping node_modules import ${id}`);
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
const resolved = resolveVuePath(id, importer);
|
|
430
|
+
if (resolved.includes("node_modules")) {
|
|
431
|
+
logger.log(`resolveId: skipping node_modules path ${resolved}`);
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
if (!filter(resolved)) {
|
|
435
|
+
logger.log(`resolveId: skipping filtered path ${resolved}`);
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
const hasCache = cache.has(resolved);
|
|
439
|
+
const fileExists = fs.existsSync(resolved);
|
|
440
|
+
logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
|
|
441
|
+
if (hasCache || fileExists) {
|
|
442
|
+
const virtualId = VIRTUAL_PREFIX + resolved + ".ts";
|
|
443
|
+
virtualToReal.set(virtualId, resolved);
|
|
444
|
+
return virtualId;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
},
|
|
449
|
+
load(id) {
|
|
450
|
+
if (id === RESOLVED_CSS_MODULE) {
|
|
451
|
+
const allCss = Array.from(collectedCss.values()).join("\n\n");
|
|
452
|
+
return allCss;
|
|
453
|
+
}
|
|
454
|
+
if (id.includes("?vue&type=style")) {
|
|
455
|
+
const [filename] = id.split("?");
|
|
456
|
+
const realPath = filename.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(filename) ?? filename.slice(VIRTUAL_PREFIX.length) : filename;
|
|
457
|
+
const compiled = cache.get(realPath);
|
|
458
|
+
if (compiled?.css) return compiled.css;
|
|
459
|
+
return "";
|
|
460
|
+
}
|
|
461
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
462
|
+
const lookupId = id.endsWith(".ts") ? id.slice(0, -3) : id;
|
|
463
|
+
const realPath = virtualToReal.get(id) ?? lookupId.slice(VIRTUAL_PREFIX.length);
|
|
464
|
+
const compiled = cache.get(realPath);
|
|
465
|
+
if (compiled) {
|
|
466
|
+
const output = generateOutput(compiled, {
|
|
467
|
+
isProduction,
|
|
468
|
+
isDev: server !== null,
|
|
469
|
+
extractCss
|
|
470
|
+
});
|
|
471
|
+
return {
|
|
472
|
+
code: output,
|
|
473
|
+
map: null
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return null;
|
|
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
|
+
},
|
|
489
|
+
async handleHotUpdate(ctx) {
|
|
490
|
+
const { file, server: server$1, read } = ctx;
|
|
491
|
+
if (file.endsWith(".vue") && filter(file)) try {
|
|
492
|
+
const source = await read();
|
|
493
|
+
const prevCompiled = cache.get(file);
|
|
494
|
+
compileFile(file, cache, {
|
|
495
|
+
sourceMap: mergedOptions.sourceMap ?? !isProduction,
|
|
496
|
+
ssr: mergedOptions.ssr ?? false
|
|
497
|
+
}, source);
|
|
498
|
+
const newCompiled = cache.get(file);
|
|
499
|
+
const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
|
|
500
|
+
logger.log(`Re-compiled: ${path.relative(root, file)} (${updateType})`);
|
|
501
|
+
const virtualId = VIRTUAL_PREFIX + file + ".ts";
|
|
502
|
+
const modules = server$1.moduleGraph.getModulesByFile(virtualId) ?? server$1.moduleGraph.getModulesByFile(file);
|
|
503
|
+
if (updateType === "style-only" && newCompiled.css) {
|
|
504
|
+
server$1.ws.send({
|
|
505
|
+
type: "custom",
|
|
506
|
+
event: "vize:update",
|
|
507
|
+
data: {
|
|
508
|
+
id: newCompiled.scopeId,
|
|
509
|
+
type: "style-only",
|
|
510
|
+
css: newCompiled.css
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
if (modules) return [...modules];
|
|
516
|
+
} catch (e) {
|
|
517
|
+
logger.error(`Re-compilation failed for ${file}:`, e);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
generateBundle(_, _bundle) {
|
|
521
|
+
if (!extractCss || collectedCss.size === 0) return;
|
|
522
|
+
const allCss = Array.from(collectedCss.values()).join("\n\n");
|
|
523
|
+
if (allCss.trim()) {
|
|
524
|
+
this.emitFile({
|
|
525
|
+
type: "asset",
|
|
526
|
+
fileName: "assets/vize-components.css",
|
|
527
|
+
source: allCss
|
|
528
|
+
});
|
|
529
|
+
logger.log(`Extracted CSS to assets/vize-components.css (${collectedCss.size} components)`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
140
533
|
}
|
|
141
|
-
|
|
534
|
+
var src_default = vize;
|
|
535
|
+
|
|
536
|
+
//#endregion
|
|
537
|
+
export { src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
|