@vixt/core 0.6.1 → 0.6.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/node/index.d.mts +12 -1
- package/dist/node/index.mjs +24 -28
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -167,10 +167,21 @@ interface AppOptions {
|
|
|
167
167
|
* The entry file relative to <srcDir>
|
|
168
168
|
* @default 'main.ts'(vue)
|
|
169
169
|
* @default 'main.tsx'(react)
|
|
170
|
-
* @example 'entry.ts'(
|
|
170
|
+
* @example 'entry.ts'(relative to '/<srcDir>/entry.ts')
|
|
171
171
|
*/
|
|
172
172
|
entryFile?: string;
|
|
173
|
+
/** The default entry code */
|
|
173
174
|
entryCode?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Whether to enable generate and transform entry file
|
|
177
|
+
* @default true
|
|
178
|
+
*/
|
|
179
|
+
transformEntryFile?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Whether to enable transform and transform index.html
|
|
182
|
+
* @default true
|
|
183
|
+
*/
|
|
184
|
+
transformIndexHtml?: boolean;
|
|
174
185
|
/**
|
|
175
186
|
* Set default configuration for `<head>`.
|
|
176
187
|
*/
|
package/dist/node/index.mjs
CHANGED
|
@@ -207,14 +207,6 @@ function resolveHead(tag, attrs) {
|
|
|
207
207
|
injectTo
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function isEmptyCode(code) {
|
|
211
|
-
if (!code) return true;
|
|
212
|
-
try {
|
|
213
|
-
return !parseAst(code, { jsx: true }).body.length;
|
|
214
|
-
} catch {
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
210
|
function resolveLoadingTemplate(options, vixt) {
|
|
219
211
|
const { loadingTemplate } = options;
|
|
220
212
|
if (loadingTemplate && fs.existsSync(loadingTemplate)) return fs.readFileSync(loadingTemplate, "utf-8");
|
|
@@ -223,14 +215,13 @@ function resolveLoadingTemplate(options, vixt) {
|
|
|
223
215
|
if (fs.existsSync(layerLoadingTemplate)) return fs.readFileSync(layerLoadingTemplate, "utf-8");
|
|
224
216
|
}
|
|
225
217
|
}
|
|
226
|
-
function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
218
|
+
function isEmptyCode(code) {
|
|
219
|
+
if (!code) return true;
|
|
220
|
+
try {
|
|
221
|
+
return !parseAst(code, { jsx: true }).body.length;
|
|
222
|
+
} catch {
|
|
223
|
+
return false;
|
|
232
224
|
}
|
|
233
|
-
return entryCode;
|
|
234
225
|
}
|
|
235
226
|
const name$7 = "vixt:app";
|
|
236
227
|
var app_default = defineVixtModule({
|
|
@@ -242,32 +233,35 @@ var app_default = defineVixtModule({
|
|
|
242
233
|
rootId: "app",
|
|
243
234
|
rootTag: "div",
|
|
244
235
|
baseURL: "/",
|
|
245
|
-
css: []
|
|
236
|
+
css: [],
|
|
237
|
+
transformEntryFile: true,
|
|
238
|
+
transformIndexHtml: true
|
|
246
239
|
},
|
|
247
240
|
setup(options, vixt) {
|
|
248
|
-
const { srcDir } = vixt.options;
|
|
249
|
-
const { entryFile,
|
|
241
|
+
const { rootDir, srcDir } = vixt.options;
|
|
242
|
+
const { entryFile, transformEntryFile, transformIndexHtml } = options;
|
|
243
|
+
const indexHtmlPath = path.resolve(rootDir, "index.html");
|
|
244
|
+
if (transformIndexHtml && !fs.existsSync(indexHtmlPath)) fs.outputFileSync(indexHtmlPath, "");
|
|
250
245
|
const relativeEntryPath = `/${path.basename(srcDir)}/${entryFile}`;
|
|
251
246
|
const absoluteEntryPath = path.resolve(srcDir, entryFile);
|
|
247
|
+
if (transformEntryFile && !fs.existsSync(absoluteEntryPath)) fs.outputFileSync(absoluteEntryPath, "");
|
|
252
248
|
const order = "pre";
|
|
253
249
|
return {
|
|
254
250
|
name: name$7,
|
|
255
251
|
enforce: order,
|
|
256
|
-
load: {
|
|
257
|
-
order,
|
|
258
|
-
handler(id) {
|
|
259
|
-
if (id === relativeEntryPath) return resolveEntryCode(options, vixt);
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
252
|
transform: {
|
|
263
253
|
order,
|
|
264
|
-
|
|
265
|
-
|
|
254
|
+
filter: { id: absoluteEntryPath },
|
|
255
|
+
handler(code) {
|
|
256
|
+
if (!transformEntryFile) return;
|
|
257
|
+
if (isEmptyCode(code)) return options.entryCode;
|
|
266
258
|
}
|
|
267
259
|
},
|
|
268
260
|
transformIndexHtml: {
|
|
269
261
|
order,
|
|
270
262
|
handler() {
|
|
263
|
+
if (!transformIndexHtml) return;
|
|
264
|
+
const { rootTag, rootId, head } = options;
|
|
271
265
|
const tags = Object.entries(head ?? {}).map(([tag, attrs]) => attrs.map((attr) => resolveHead(tag, attr))).flat();
|
|
272
266
|
const loadingTemplate = resolveLoadingTemplate(options, vixt);
|
|
273
267
|
return [
|
|
@@ -482,19 +476,21 @@ var virtual_app_config_default = defineVixtModule({
|
|
|
482
476
|
i++;
|
|
483
477
|
}
|
|
484
478
|
}
|
|
485
|
-
const { baseURL = "/", rootId = "app" } = vixt.options.app ?? {};
|
|
486
479
|
return {
|
|
487
480
|
name: name$3,
|
|
488
481
|
resolveId(id) {
|
|
489
482
|
if (id === virtualModuleId$2) return resolvedVirtualModuleId$2;
|
|
490
483
|
},
|
|
491
484
|
load(id) {
|
|
492
|
-
if (id === resolvedVirtualModuleId$2)
|
|
485
|
+
if (id === resolvedVirtualModuleId$2) {
|
|
486
|
+
const { baseURL = "/", rootId = "app" } = vixt.options.app ?? {};
|
|
487
|
+
return `
|
|
493
488
|
import { defu } from 'defu'
|
|
494
489
|
${appConfigsImportTemplate}
|
|
495
490
|
const appConfig = defu(${appConfigsMergeTemplate}{ baseURL: '${baseURL}', rootId: '${rootId}' })
|
|
496
491
|
export default appConfig
|
|
497
492
|
`;
|
|
493
|
+
}
|
|
498
494
|
}
|
|
499
495
|
};
|
|
500
496
|
}
|