@vizejs/nuxt 0.108.0 → 0.112.0

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.mts CHANGED
@@ -2,19 +2,132 @@ import { MuseaOptions, MuseaOptions as MuseaOptions$1 } from "@vizejs/vite-plugi
2
2
  import * as _$nuxt_schema0 from "nuxt/schema";
3
3
  import { NuxtMuseaOptions, NuxtMuseaOptions as NuxtMuseaOptions$1 } from "@vizejs/musea-nuxt";
4
4
 
5
- //#region src/index.d.ts
5
+ //#region src/compiler-options.d.ts
6
+ type VizeNuxtPattern = string | RegExp;
7
+ /**
8
+ * Nuxt-facing mirror of the public `@vizejs/vite-plugin` options.
9
+ *
10
+ * Keeping this shape local lets the Nuxt module expose compiler configuration
11
+ * without requiring the sibling package's generated declaration files to exist
12
+ * during monorepo lint runs.
13
+ */
14
+ interface VizeNuxtCompilerOptions {
15
+ /** Override the public base used for dev-time asset URLs. */
16
+ devUrlBase?: string;
17
+ /** Files to include in compilation. */
18
+ include?: VizeNuxtPattern | VizeNuxtPattern[];
19
+ /** Files to exclude from compilation. */
20
+ exclude?: VizeNuxtPattern | VizeNuxtPattern[];
21
+ /** Force production mode. */
22
+ isProduction?: boolean;
23
+ /** Enable SSR mode. */
24
+ ssr?: boolean;
25
+ /** Enable source map generation. */
26
+ sourceMap?: boolean;
27
+ /** Enable Vapor mode compilation. */
28
+ vapor?: boolean;
29
+ /** Treat lowercase non-HTML tags as custom renderer elements. */
30
+ customRenderer?: boolean;
31
+ /** Root directory to scan for .vue files. */
32
+ root?: string;
33
+ /** Glob patterns to scan for .vue files during pre-compilation. */
34
+ scanPatterns?: string[];
35
+ /** Maximum number of Vue files to compile in a single native batch. */
36
+ precompileBatchSize?: number;
37
+ /** Glob patterns to ignore during pre-compilation. */
38
+ ignorePatterns?: string[];
39
+ /** Config file search mode. */
40
+ configMode?: "root" | "auto" | false;
41
+ /** Custom config file path. */
42
+ configFile?: string;
43
+ /** Handle .vue files in node_modules during on-demand compilation. */
44
+ handleNodeModulesVue?: boolean;
45
+ /** Enable debug logging. */
46
+ debug?: boolean;
47
+ }
48
+ //#endregion
49
+ //#region src/options.d.ts
50
+ interface VizeNuxtBridgeOptions {
51
+ /**
52
+ * Re-apply Nuxt auto-import injection to Vize virtual Vue modules.
53
+ * @default true
54
+ */
55
+ autoImports?: boolean;
56
+ /**
57
+ * Re-apply Nuxt component auto-import resolution to Vize virtual Vue modules.
58
+ * @default true
59
+ */
60
+ components?: boolean;
61
+ /**
62
+ * Re-apply @nuxtjs/i18n helper injection to Vize virtual Vue modules.
63
+ * @default true
64
+ */
65
+ i18n?: boolean;
66
+ /**
67
+ * Stabilize Nuxt generated async-data keys between client and SSR transforms.
68
+ * @default true
69
+ */
70
+ stableInjectedKeys?: boolean;
71
+ }
72
+ interface VizeNuxtUnoCssOptions {
73
+ /**
74
+ * Feed the original .vue source to UnoCSS extraction-only plugins so
75
+ * attributify syntax survives Vize's render-function output.
76
+ *
77
+ * Set to `false` to skip reading SFC source files. Use an object to tune the
78
+ * maximum source size read into Node.
79
+ *
80
+ * @default true
81
+ */
82
+ originalSource?: boolean | {
83
+ /**
84
+ * Maximum original .vue source size to append for UnoCSS extraction.
85
+ * @default 2097152
86
+ */
87
+ maxBytes?: number;
88
+ };
89
+ }
90
+ interface VizeNuxtDevOptions {
91
+ /**
92
+ * Remove broken duplicate/unsafe stylesheet links from Nuxt dev SSR HTML
93
+ * when Vize is the Vue compiler.
94
+ *
95
+ * @default true
96
+ */
97
+ stylesheetLinks?: boolean;
98
+ }
6
99
  interface VizeNuxtOptions {
7
100
  /**
8
101
  * Enable/disable the Vize compiler (Vue SFC compilation via Vite plugin).
9
- * Set to `false` to use Vue's default SFC compiler instead.
102
+ * Pass an object to configure the underlying `@vizejs/vite-plugin`.
103
+ *
10
104
  * @default true
11
105
  */
12
- compiler?: boolean;
106
+ compiler?: boolean | VizeNuxtCompilerOptions;
107
+ /**
108
+ * Nuxt compatibility bridges for transforms that normally skip Rollup
109
+ * virtual module ids.
110
+ *
111
+ * @default true
112
+ */
113
+ bridge?: boolean | VizeNuxtBridgeOptions;
114
+ /**
115
+ * UnoCSS bridge options for Vize virtual Vue modules.
116
+ *
117
+ * @default true
118
+ */
119
+ unocss?: boolean | VizeNuxtUnoCssOptions;
120
+ /**
121
+ * Dev-server integration options.
122
+ */
123
+ dev?: VizeNuxtDevOptions;
13
124
  /**
14
125
  * Musea gallery options.
15
- * Set to `false` to disable musea.
126
+ * Set to `true` to enable Musea with default options.
127
+ *
128
+ * @default false
16
129
  */
17
- musea?: MuseaOptions$1 | false;
130
+ musea?: boolean | MuseaOptions$1;
18
131
  /**
19
132
  * Nuxt mock options for musea gallery.
20
133
  * NOTE: In Nuxt context, nuxtMusea mocks are NOT added as a global Vite plugin
@@ -23,6 +136,8 @@ interface VizeNuxtOptions {
23
136
  */
24
137
  nuxtMusea?: NuxtMuseaOptions$1;
25
138
  }
139
+ //#endregion
140
+ //#region src/index.d.ts
26
141
  declare const _default: _$nuxt_schema0.NuxtModule<VizeNuxtOptions, VizeNuxtOptions, false>;
27
142
  //#endregion
28
- export { type MuseaOptions, type NuxtMuseaOptions, VizeNuxtOptions, _default as default };
143
+ export { type MuseaOptions, type NuxtMuseaOptions, type VizeNuxtBridgeOptions, type VizeNuxtCompilerOptions, type VizeNuxtDevOptions, type VizeNuxtOptions, type VizeNuxtUnoCssOptions, _default as default };
package/dist/index.mjs CHANGED
@@ -292,12 +292,14 @@ function buildNuxtDevAssetBase(baseURL = "/", buildAssetsDir = "/_nuxt/") {
292
292
  const normalizedAssetsDir = normalizeUrlPrefix(buildAssetsDir);
293
293
  return normalizedBase === "/" ? normalizedAssetsDir : normalizeUrlPrefix(`${normalizedBase}${normalizedAssetsDir.replace(/^\//, "")}`);
294
294
  }
295
- function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nuxt/") {
296
- return {
295
+ function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nuxt/", overrides = {}) {
296
+ const defaults = {
297
297
  devUrlBase: buildNuxtDevAssetBase(baseURL, buildAssetsDir),
298
298
  root: rootDir,
299
299
  scanPatterns: []
300
300
  };
301
+ for (const [key, value] of Object.entries(overrides)) if (value !== void 0) defaults[key] = value;
302
+ return defaults;
301
303
  }
302
304
  function isVizeVirtualVueModuleId(id) {
303
305
  return id.startsWith("\0") && /\.vue\.ts(?:\?|$)/.test(id);
@@ -318,6 +320,54 @@ function normalizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
318
320
  return `'$${buildStableNuxtKey(normalizedId, index)}' ${NUXT_INJECTED_MARKER}`;
319
321
  });
320
322
  }
323
+ //#endregion
324
+ //#region src/options.ts
325
+ const DEFAULT_NUXT_BRIDGE_OPTIONS = {
326
+ autoImports: true,
327
+ components: true,
328
+ i18n: true,
329
+ stableInjectedKeys: true
330
+ };
331
+ const DEFAULT_NUXT_UNOCSS_OPTIONS = { originalSource: {} };
332
+ const DEFAULT_NUXT_DEV_OPTIONS = { stylesheetLinks: true };
333
+ function resolveNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, compiler) {
334
+ if (compiler === false) return false;
335
+ return buildNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, typeof compiler === "object" && compiler != null ? compiler : {});
336
+ }
337
+ function resolveNuxtBridgeOptions(bridge) {
338
+ if (bridge === false) return {
339
+ autoImports: false,
340
+ components: false,
341
+ i18n: false,
342
+ stableInjectedKeys: false
343
+ };
344
+ if (bridge === true || bridge == null) return { ...DEFAULT_NUXT_BRIDGE_OPTIONS };
345
+ return {
346
+ autoImports: bridge.autoImports ?? DEFAULT_NUXT_BRIDGE_OPTIONS.autoImports,
347
+ components: bridge.components ?? DEFAULT_NUXT_BRIDGE_OPTIONS.components,
348
+ i18n: bridge.i18n ?? DEFAULT_NUXT_BRIDGE_OPTIONS.i18n,
349
+ stableInjectedKeys: bridge.stableInjectedKeys ?? DEFAULT_NUXT_BRIDGE_OPTIONS.stableInjectedKeys
350
+ };
351
+ }
352
+ function resolveNuxtUnoCssOptions(unocss) {
353
+ if (unocss === false) return false;
354
+ if (unocss === true || unocss == null) return { ...DEFAULT_NUXT_UNOCSS_OPTIONS };
355
+ const originalSource = unocss.originalSource;
356
+ if (originalSource === false) return { originalSource: false };
357
+ if (originalSource === true || originalSource == null) return { originalSource: {} };
358
+ return { originalSource };
359
+ }
360
+ function resolveNuxtDevOptions(dev) {
361
+ return {
362
+ ...DEFAULT_NUXT_DEV_OPTIONS,
363
+ ...dev
364
+ };
365
+ }
366
+ function resolveNuxtMuseaOptions(musea) {
367
+ if (musea === true) return {};
368
+ if (musea === false || musea == null) return false;
369
+ return musea;
370
+ }
321
371
  function readTextFile(filePath) {
322
372
  return fs.readFileSync(filePath, "utf-8");
323
373
  }
@@ -383,21 +433,23 @@ var src_default = defineNuxtModule({
383
433
  configKey: "vize"
384
434
  },
385
435
  defaults: {
386
- musea: {
387
- include: ["**/*.art.vue"],
388
- inlineArt: false
389
- },
436
+ musea: false,
390
437
  nuxtMusea: { route: { path: "/" } }
391
438
  },
392
439
  setup(options, nuxt) {
393
440
  const resolver = createResolver(import.meta.url);
441
+ const bridgeOptions = resolveNuxtBridgeOptions(options.bridge);
442
+ const devOptions = resolveNuxtDevOptions(options.dev);
443
+ const museaOptions = resolveNuxtMuseaOptions(options.musea);
444
+ const unocssOptions = resolveNuxtUnoCssOptions(options.unocss);
394
445
  nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
395
- if (options.compiler !== false) {
396
- const compilerOptions = buildNuxtCompilerOptions(nuxt.options.rootDir, nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir);
446
+ const compilerOptions = resolveNuxtCompilerOptions(nuxt.options.rootDir, nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir, options.compiler);
447
+ if (compilerOptions !== false) {
397
448
  nuxt.options.vite.plugins.push(vize(compilerOptions));
398
- if (nuxt.options.dev) {
449
+ if (nuxt.options.dev && devOptions.stylesheetLinks) {
450
+ const devAssetBase = compilerOptions.devUrlBase ?? buildNuxtDevAssetBase(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir);
399
451
  nuxt.options.nitro.virtual ||= {};
400
- nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(compilerOptions.devUrlBase)};`;
452
+ nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
401
453
  addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
402
454
  }
403
455
  nuxt.hook("vite:configResolved", (config) => {
@@ -405,40 +457,44 @@ var src_default = defineNuxtModule({
405
457
  const p = config.plugins[i];
406
458
  const name = p && typeof p === "object" && "name" in p ? p.name : "";
407
459
  if (name === "vite:vue") config.plugins.splice(i, 1);
408
- else if (name === "nuxt:compiler:keyed-functions") patchNuxtKeyedFunctionsPlugin(p);
460
+ else if (bridgeOptions.stableInjectedKeys && name === "nuxt:compiler:keyed-functions") patchNuxtKeyedFunctionsPlugin(p);
409
461
  }
410
462
  });
411
463
  }
412
464
  let unimportCtx = null;
413
- nuxt.hook("imports:context", (ctx) => {
465
+ if (bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
414
466
  unimportCtx = ctx;
415
467
  });
416
- const nuxtComponentResolver = createNuxtComponentResolver({
468
+ const nuxtComponentResolver = bridgeOptions.components ? createNuxtComponentResolver({
417
469
  buildDir: nuxt.options.buildDir,
418
470
  moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
419
471
  rootDir: nuxt.options.rootDir
420
- });
421
- nuxt.hook("components:extend", (comps) => {
472
+ }) : null;
473
+ if (nuxtComponentResolver) nuxt.hook("components:extend", (comps) => {
422
474
  nuxtComponentResolver.register(comps);
423
475
  });
424
- addVitePlugin({
476
+ if (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys) addVitePlugin({
425
477
  name: "vizejs:nuxt-transform-bridge",
426
478
  enforce: "post",
427
479
  async transform(code, id) {
428
480
  if (!isVizeVirtualVueModuleId(id)) return;
429
481
  let result = code;
430
482
  let changed = false;
431
- const nextComponentResult = injectNuxtComponentImports(result, (name) => {
432
- return nuxtComponentResolver.resolve(name);
433
- });
434
- if (nextComponentResult !== result) {
435
- result = nextComponentResult;
436
- changed = true;
483
+ if (nuxtComponentResolver) {
484
+ const nextComponentResult = injectNuxtComponentImports(result, (name) => {
485
+ return nuxtComponentResolver.resolve(name);
486
+ });
487
+ if (nextComponentResult !== result) {
488
+ result = nextComponentResult;
489
+ changed = true;
490
+ }
437
491
  }
438
- const nextResult = injectNuxtI18nHelpers(result);
439
- if (nextResult !== result) {
440
- result = nextResult;
441
- changed = true;
492
+ if (bridgeOptions.i18n) {
493
+ const nextResult = injectNuxtI18nHelpers(result);
494
+ if (nextResult !== result) {
495
+ result = nextResult;
496
+ changed = true;
497
+ }
442
498
  }
443
499
  if (unimportCtx) try {
444
500
  const injected = await unimportCtx.injectImports(result, id);
@@ -447,10 +503,12 @@ var src_default = defineNuxtModule({
447
503
  changed = true;
448
504
  }
449
505
  } catch {}
450
- const stableKeyResult = normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
451
- if (stableKeyResult !== result) {
452
- result = stableKeyResult;
453
- changed = true;
506
+ if (bridgeOptions.stableInjectedKeys) {
507
+ const stableKeyResult = normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
508
+ if (stableKeyResult !== result) {
509
+ result = stableKeyResult;
510
+ changed = true;
511
+ }
454
512
  }
455
513
  if (changed) return {
456
514
  code: result,
@@ -458,7 +516,7 @@ var src_default = defineNuxtModule({
458
516
  };
459
517
  }
460
518
  });
461
- addVitePlugin({
519
+ if (unocssOptions !== false) addVitePlugin({
462
520
  name: "vizejs:unocss-bridge",
463
521
  configResolved(config) {
464
522
  for (const plugin of config.plugins) if (plugin.name?.startsWith("unocss:") && typeof plugin.transform === "function") {
@@ -468,7 +526,7 @@ var src_default = defineNuxtModule({
468
526
  if (isVizeVirtualVueModuleId(id)) {
469
527
  const normalizedId = normalizeVizeVirtualVueModuleId(id);
470
528
  let effectiveCode = code;
471
- if (isExtractionOnly) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId);
529
+ if (isExtractionOnly && unocssOptions.originalSource !== false) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId, { maxBytes: unocssOptions.originalSource.maxBytes });
472
530
  return origTransform.call(this, effectiveCode, normalizedId, ...args);
473
531
  }
474
532
  return origTransform.call(this, code, id, ...args);
@@ -476,9 +534,9 @@ var src_default = defineNuxtModule({
476
534
  }
477
535
  }
478
536
  });
479
- if (options.musea !== false) {
480
- const museaBasePath = options.musea && typeof options.musea === "object" && "basePath" in options.musea ? options.musea.basePath : "/__musea__";
481
- nuxt.options.vite.plugins.push(...musea(options.musea || {}));
537
+ if (museaOptions !== false) {
538
+ const museaBasePath = "basePath" in museaOptions ? museaOptions.basePath : "/__musea__";
539
+ nuxt.options.vite.plugins.push(...musea(museaOptions));
482
540
  nuxt.hook("listen", (_server, listener) => {
483
541
  const url = listener.url?.replace(/\/$/, "") || "http://localhost:3000";
484
542
  console.log(` \x1b[36m➜\x1b[0m \x1b[1mMusea Gallery:\x1b[0m \x1b[36m${url}${museaBasePath}\x1b[0m`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.108.0",
3
+ "version": "0.112.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -40,11 +40,11 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@nuxt/kit": "4.4.5",
44
- "@vizejs/musea-nuxt": "0.108.0",
45
- "@vizejs/vite-plugin": "0.108.0",
46
- "@vizejs/vite-plugin-musea": "0.108.0",
47
- "vize": "0.108.0"
43
+ "@nuxt/kit": "4.4.6",
44
+ "@vizejs/musea-nuxt": "0.112.0",
45
+ "@vizejs/vite-plugin": "0.112.0",
46
+ "@vizejs/vite-plugin-musea": "0.112.0",
47
+ "vize": "0.112.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",