@volpe/astro-svelte-spa 0.1.5 → 0.1.7
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/index.js +13 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const VIRTUAL_MODULE_ID = "virtual:svelte-routes";
|
|
|
5
5
|
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
6
6
|
|
|
7
7
|
const VIRTUAL_SPA_ID = "virtual:svelte-spa";
|
|
8
|
+
const RESOLVED_SPA_ID = "virtual:svelte-spa.svelte";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @typedef {Object} RouteNode
|
|
@@ -296,15 +297,16 @@ function generateAppComponent() {
|
|
|
296
297
|
/**
|
|
297
298
|
* Vite plugin for file-based routing with svelte5-router in Astro
|
|
298
299
|
* @param {Object} options - Plugin options
|
|
299
|
-
* @param {string} [options.
|
|
300
|
+
* @param {string} [options.dir] - Directory to scan for pages (defaults to "src/svelte")
|
|
301
|
+
* @param {string} [options.base] - URL base path for routes (defaults to "/svelte-app")
|
|
300
302
|
* @returns {import('vite').Plugin}
|
|
301
303
|
*/
|
|
302
304
|
export function plugin(options = {}) {
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
+
const dir = options.dir?.replace(/\/$/, "") || "src/svelte";
|
|
306
|
+
const base = options.base?.replace(/\/$/, "") || "/svelte-app";
|
|
305
307
|
|
|
306
308
|
const rootDir = process.cwd();
|
|
307
|
-
const pagesDir = path.resolve(rootDir,
|
|
309
|
+
const pagesDir = path.resolve(rootDir, dir);
|
|
308
310
|
const typesPath = path.resolve(rootDir, "src/svelte-routes.d.ts");
|
|
309
311
|
|
|
310
312
|
generatePageFiles(pagesDir);
|
|
@@ -314,19 +316,19 @@ export function plugin(options = {}) {
|
|
|
314
316
|
enforce: "pre",
|
|
315
317
|
|
|
316
318
|
buildStart() {
|
|
317
|
-
generateTypesFile(pagesDir, typesPath,
|
|
319
|
+
generateTypesFile(pagesDir, typesPath, base);
|
|
318
320
|
},
|
|
319
321
|
|
|
320
322
|
configureServer(server) {
|
|
321
|
-
generateTypesFile(pagesDir, typesPath,
|
|
323
|
+
generateTypesFile(pagesDir, typesPath, base);
|
|
322
324
|
|
|
323
|
-
const watchPath =
|
|
325
|
+
const watchPath = `/${dir}/`;
|
|
324
326
|
server.watcher.on("all", (event, filePath) => {
|
|
325
327
|
if (
|
|
326
328
|
filePath.includes(watchPath) &&
|
|
327
329
|
(filePath.endsWith("page.svelte") || filePath.endsWith("layout.svelte") || filePath.endsWith("404.svelte"))
|
|
328
330
|
) {
|
|
329
|
-
generateTypesFile(pagesDir, typesPath,
|
|
331
|
+
generateTypesFile(pagesDir, typesPath, base);
|
|
330
332
|
|
|
331
333
|
const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
332
334
|
if (mod) {
|
|
@@ -353,15 +355,15 @@ export function plugin(options = {}) {
|
|
|
353
355
|
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
354
356
|
}
|
|
355
357
|
if (id === VIRTUAL_SPA_ID) {
|
|
356
|
-
return
|
|
358
|
+
return RESOLVED_SPA_ID;
|
|
357
359
|
}
|
|
358
360
|
},
|
|
359
361
|
|
|
360
362
|
load(id) {
|
|
361
363
|
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
362
|
-
return generateRoutesModule(pagesDir,
|
|
364
|
+
return generateRoutesModule(pagesDir, base);
|
|
363
365
|
}
|
|
364
|
-
if (id ===
|
|
366
|
+
if (id === RESOLVED_SPA_ID) {
|
|
365
367
|
return generateAppComponent();
|
|
366
368
|
}
|
|
367
369
|
},
|