@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.
@@ -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'(means '/<srcDir>/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
  */
@@ -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 resolveEntryCode(options, vixt) {
227
- const { entryCode, entryFile } = options;
228
- for (const layer of vixt._layers) {
229
- const layerEntryPath = path.resolve(layer.config.srcDir, entryFile);
230
- const code = fs.existsSync(layerEntryPath) && fs.readFileSync(layerEntryPath, "utf-8") || "";
231
- if (!isEmptyCode(code)) return code;
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, rootTag, rootId, head } = options;
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
- handler(code, id) {
265
- if (id === absoluteEntryPath && isEmptyCode(code)) return resolveEntryCode(options, vixt);
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) return `
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.6.3",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://soullyoko.github.io/vixt/",