vite-plugin-vue-layouts-next
Advanced tools
Comparing version
@@ -6,2 +6,3 @@ /** | ||
import type { RouteRecordRaw } from 'vue-router' | ||
export function setupLayouts(routes: RouteRecordRaw[]): RouteRecordRaw[] | ||
@@ -15,2 +16,2 @@ } | ||
export function setupLayouts(routes: RouteRecordRaw[]): RouteRecordRaw[] | ||
} | ||
} |
@@ -36,6 +36,6 @@ import { Plugin } from 'vite'; | ||
} | ||
type FileContainer = { | ||
interface FileContainer { | ||
path: string; | ||
files: string[]; | ||
}; | ||
} | ||
type UserOptions = Partial<Options>; | ||
@@ -42,0 +42,0 @@ interface ResolvedOptions extends Options { |
@@ -1,45 +0,10 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var index_exports = {}; | ||
__export(index_exports, { | ||
ClientSideLayout: () => ClientSideLayout, | ||
default: () => Layout, | ||
defaultImportMode: () => defaultImportMode | ||
}); | ||
module.exports = __toCommonJS(index_exports); | ||
var import_node_path3 = require("path"); | ||
import { resolve as resolve2 } from "node:path"; | ||
import process from "node:process"; | ||
// src/clientSide.ts | ||
var import_node_path = require("path"); | ||
import { posix } from "node:path"; | ||
function normalizePath(path) { | ||
path = path.startsWith("/") ? path : `/${path}`; | ||
return import_node_path.posix.normalize(path); | ||
return posix.normalize(path); | ||
} | ||
@@ -122,8 +87,8 @@ async function createVirtualGlob(target, isSync) { | ||
// src/files.ts | ||
var import_fast_glob2 = __toESM(require("fast-glob")); | ||
import fg2 from "fast-glob"; | ||
// src/utils.ts | ||
var import_node_path2 = require("path"); | ||
var import_debug = __toESM(require("debug")); | ||
var import_fast_glob = __toESM(require("fast-glob")); | ||
import { resolve } from "node:path"; | ||
import Debug from "debug"; | ||
import fg from "fast-glob"; | ||
function extensionsToGlob(extensions) { | ||
@@ -135,3 +100,3 @@ return extensions.length > 1 ? `{${extensions.join(",")}}` : extensions[0] || ""; | ||
} | ||
var debug = (0, import_debug.default)("vite-plugin-layouts"); | ||
var debug = Debug("vite-plugin-layouts"); | ||
function resolveDirs(dirs, root) { | ||
@@ -144,7 +109,7 @@ if (dirs === null) | ||
if (dir.includes("**")) { | ||
const matches = import_fast_glob.default.sync(dir, { onlyDirectories: true }); | ||
const matches = fg.sync(dir, { onlyDirectories: true }); | ||
for (const match of matches) | ||
dirsResolved.push(normalizePath2((0, import_node_path2.resolve)(root, match))); | ||
dirsResolved.push(normalizePath2(resolve(root, match))); | ||
} else { | ||
dirsResolved.push(normalizePath2((0, import_node_path2.resolve)(root, dir))); | ||
dirsResolved.push(normalizePath2(resolve(root, dir))); | ||
} | ||
@@ -163,3 +128,3 @@ } | ||
debug(extensions); | ||
const files = await (0, import_fast_glob2.default)(`**/*.${ext}`, { | ||
const files = await fg2(`**/*.${ext}`, { | ||
ignore: ["node_modules", ".git", "**/__*__/*", ...exclude], | ||
@@ -173,3 +138,3 @@ onlyFiles: true, | ||
// src/importCode.ts | ||
var import_path = require("path"); | ||
import { join, parse } from "node:path"; | ||
function getImportCode(files, options) { | ||
@@ -182,4 +147,4 @@ const imports = []; | ||
const path = __.path.substr(0, 1) === "/" ? `${__.path}/${file}` : `/${__.path}/${file}`; | ||
const parsed = (0, import_path.parse)(file); | ||
const name = (0, import_path.join)(parsed.dir, parsed.name).replace(/\\/g, "/"); | ||
const parsed = parse(file); | ||
const name = join(parsed.dir, parsed.name).replace(/\\/g, "/"); | ||
if (options.importMode(name) === "sync") { | ||
@@ -307,5 +272,5 @@ const variable = `__layout_${id}`; | ||
watcher.add(options.layoutsDirs); | ||
const reloadModule = (module2, path = "*") => { | ||
if (module2) { | ||
moduleGraph.invalidateModule(module2); | ||
const reloadModule = (module, path = "*") => { | ||
if (module) { | ||
moduleGraph.invalidateModule(module); | ||
if (ws) { | ||
@@ -323,4 +288,4 @@ ws.send({ | ||
debug("reload", path); | ||
const module2 = moduleGraph.getModuleById(MODULE_ID_VIRTUAL); | ||
reloadModule(module2); | ||
const module = moduleGraph.getModuleById(MODULE_ID_VIRTUAL); | ||
reloadModule(module); | ||
} | ||
@@ -345,3 +310,3 @@ }; | ||
for (const dir of layoutDirs) { | ||
const layoutsDirPath = dir.substr(0, 1) === "/" ? normalizePath2(dir) : normalizePath2((0, import_node_path3.resolve)(config.root, dir)); | ||
const layoutsDirPath = dir.substr(0, 1) === "/" ? normalizePath2(dir) : normalizePath2(resolve2(config.root, dir)); | ||
debug("Loading Layout Dir: %O", layoutsDirPath); | ||
@@ -391,6 +356,6 @@ const _f = await getFilesFromPath(layoutsDirPath, options); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
export { | ||
ClientSideLayout, | ||
Layout as default, | ||
defaultImportMode | ||
}); | ||
}; |
{ | ||
"name": "vite-plugin-vue-layouts-next", | ||
"version": "0.1.1", | ||
"type": "module", | ||
"version": "0.1.2", | ||
"description": "Router-based layout plugin for Vite and Vue, supports the latest versions.", | ||
@@ -57,3 +58,5 @@ "author": "loicduong <npm@relate.dev>", | ||
"example:build-vitesse": "npm -C examples/vitesse run build", | ||
"example:serve-vitesse": "npm -C examples/vitesse run preview" | ||
"example:serve-vitesse": "npm -C examples/vitesse run preview", | ||
"lint": "eslint", | ||
"lint:fix": "eslint --fix" | ||
}, | ||
@@ -66,19 +69,19 @@ "peerDependencies": { | ||
"dependencies": { | ||
"debug": "^4.4.0", | ||
"debug": "^4.4.1", | ||
"fast-glob": "^3.3.3" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^4.12.0", | ||
"@antfu/eslint-config": "^4.13.1", | ||
"@types/debug": "^4.1.12", | ||
"@types/node": "^22.15.3", | ||
"@types/node": "^22.15.18", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^9.26.0", | ||
"eslint-plugin-format": "^1.0.1", | ||
"rollup": "^4.40.1", | ||
"rollup": "^4.40.2", | ||
"tsup": "^8.4.0", | ||
"typescript": "^5.8.3", | ||
"vite": "^6.3.3", | ||
"vue": "^3.5.13", | ||
"vite": "^6.3.5", | ||
"vue": "^3.5.14", | ||
"vue-router": "^4.5.1" | ||
} | ||
} |
@@ -53,4 +53,4 @@ # vite-plugin-vue-layouts-next | ||
```js | ||
import { setupLayouts } from 'virtual:generated-layouts' | ||
import { createRouter } from 'vue-router' | ||
import { setupLayouts } from 'virtual:generated-layouts' | ||
import generatedRoutes from '~pages' | ||
@@ -69,4 +69,4 @@ | ||
```js | ||
import { setupLayouts } from 'virtual:generated-layouts' | ||
import { createRouter } from 'vue-router' | ||
import { setupLayouts } from 'virtual:generated-layouts' | ||
import { routes } from 'vue-router/auto-routes' | ||
@@ -73,0 +73,0 @@ |
49833
31.5%10
25%1086
43.27%Yes
NaNUpdated