@vizejs/nuxt 0.26.0 → 0.28.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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { addVitePlugin, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
|
|
3
3
|
import vize from "@vizejs/vite-plugin";
|
|
4
4
|
import { musea } from "@vizejs/vite-plugin-musea";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
@@ -273,6 +273,18 @@ function injectNuxtI18nHelpers(code) {
|
|
|
273
273
|
return code.slice(0, setupBodyStart) + `\nconst { ${usedSpecifiers.join(", ")} } = useI18n();\n` + code.slice(setupBodyStart);
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/utils.ts
|
|
278
|
+
function normalizeUrlPrefix(value) {
|
|
279
|
+
const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
|
|
280
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
281
|
+
}
|
|
282
|
+
function buildNuxtDevAssetBase(baseURL = "/", buildAssetsDir = "/_nuxt/") {
|
|
283
|
+
const normalizedBase = normalizeUrlPrefix(baseURL);
|
|
284
|
+
const normalizedAssetsDir = normalizeUrlPrefix(buildAssetsDir);
|
|
285
|
+
return normalizedBase === "/" ? normalizedAssetsDir : normalizeUrlPrefix(`${normalizedBase}${normalizedAssetsDir.replace(/^\//, "")}`);
|
|
286
|
+
}
|
|
287
|
+
|
|
276
288
|
//#endregion
|
|
277
289
|
//#region src/index.ts
|
|
278
290
|
var src_default = defineNuxtModule({
|
|
@@ -288,9 +300,16 @@ var src_default = defineNuxtModule({
|
|
|
288
300
|
nuxtMusea: { route: { path: "/" } }
|
|
289
301
|
},
|
|
290
302
|
setup(options, nuxt) {
|
|
303
|
+
const resolver = createResolver(import.meta.url);
|
|
291
304
|
nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
|
|
292
305
|
if (options.compiler !== false) {
|
|
293
|
-
nuxt.options.
|
|
306
|
+
const devAssetBase = buildNuxtDevAssetBase(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir);
|
|
307
|
+
nuxt.options.vite.plugins.push(vize({ devUrlBase: devAssetBase }));
|
|
308
|
+
if (nuxt.options.dev) {
|
|
309
|
+
nuxt.options.nitro.virtual ||= {};
|
|
310
|
+
nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
|
|
311
|
+
addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
|
|
312
|
+
}
|
|
294
313
|
nuxt.hook("vite:configResolved", (config) => {
|
|
295
314
|
for (let i = config.plugins.length - 1; i >= 0; i--) {
|
|
296
315
|
const p = config.plugins[i];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineNitroPlugin } from "nitropack/runtime";
|
|
2
|
+
import { devAssetBase } from "#vizejs/nuxt/dev-stylesheet-links-config";
|
|
3
|
+
|
|
4
|
+
//#region src/dev-html.ts
|
|
5
|
+
function sanitizeNuxtDevStylesheetLinks(html, buildAssetsDir = "/_nuxt/") {
|
|
6
|
+
function normalizeUrlPrefix(value) {
|
|
7
|
+
const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
|
|
8
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
9
|
+
}
|
|
10
|
+
const normalizedAssetsDir = normalizeUrlPrefix(buildAssetsDir);
|
|
11
|
+
const seenHrefs = new Set();
|
|
12
|
+
function shouldKeepHref(href) {
|
|
13
|
+
if (seenHrefs.has(href)) return false;
|
|
14
|
+
seenHrefs.add(href);
|
|
15
|
+
if (!href.startsWith(normalizedAssetsDir)) return true;
|
|
16
|
+
const pathPart = href.slice(normalizedAssetsDir.length).split("?")[0].split("#")[0];
|
|
17
|
+
let decodedPath = pathPart;
|
|
18
|
+
try {
|
|
19
|
+
decodedPath = decodeURIComponent(pathPart);
|
|
20
|
+
} catch {}
|
|
21
|
+
if (decodedPath.includes("\0")) return false;
|
|
22
|
+
return pathPart.startsWith("@fs/") || pathPart.startsWith("@id/") || pathPart.startsWith("assets/") || pathPart.startsWith("virtual:") || /^__[\w.-]+\.css$/i.test(pathPart) || /^[\w.-]+\.css$/i.test(pathPart);
|
|
23
|
+
}
|
|
24
|
+
return html.replace(/<link\b(?=[^>]*\brel=(["'])stylesheet\1)[^>]*\bhref=(["'])(.*?)\2[^>]*>/gi, (tag, _relQuote, _hrefQuote, href) => shouldKeepHref(href) ? tag : "");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/runtime/server/dev-stylesheet-links.ts
|
|
29
|
+
var dev_stylesheet_links_default = defineNitroPlugin((nitroApp) => {
|
|
30
|
+
nitroApp.hooks.hook("render:response", (response) => {
|
|
31
|
+
if (typeof response?.body !== "string" || !response.body.includes("<link")) return;
|
|
32
|
+
response.body = sanitizeNuxtDevStylesheetLinks(response.body, devAssetBase);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { dev_stylesheet_links_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@nuxt/kit": "^4.0.0",
|
|
37
|
-
"@vizejs/vite-plugin
|
|
38
|
-
"@vizejs/musea
|
|
39
|
-
"@vizejs/
|
|
40
|
-
"vize": "0.
|
|
37
|
+
"@vizejs/vite-plugin": "0.28.0",
|
|
38
|
+
"@vizejs/vite-plugin-musea": "0.28.0",
|
|
39
|
+
"@vizejs/musea-nuxt": "0.28.0",
|
|
40
|
+
"vize": "0.28.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsdown": "^0.9.0",
|