@volpe/astro-svelte-spa 0.1.6 → 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.
Files changed (2) hide show
  1. package/index.js +10 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -297,15 +297,16 @@ function generateAppComponent() {
297
297
  /**
298
298
  * Vite plugin for file-based routing with svelte5-router in Astro
299
299
  * @param {Object} options - Plugin options
300
- * @param {string} [options.basePath] - Base path for all routes (defaults to "/svelte-app")
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")
301
302
  * @returns {import('vite').Plugin}
302
303
  */
303
304
  export function plugin(options = {}) {
304
- const basePath = options.basePath?.replace(/\/$/, "") || "/svelte-app";
305
- const dirSuffix = basePath.replace(/^\//, "");
305
+ const dir = options.dir?.replace(/\/$/, "") || "src/svelte";
306
+ const base = options.base?.replace(/\/$/, "") || "/svelte-app";
306
307
 
307
308
  const rootDir = process.cwd();
308
- const pagesDir = path.resolve(rootDir, "src/pages", dirSuffix);
309
+ const pagesDir = path.resolve(rootDir, dir);
309
310
  const typesPath = path.resolve(rootDir, "src/svelte-routes.d.ts");
310
311
 
311
312
  generatePageFiles(pagesDir);
@@ -315,19 +316,19 @@ export function plugin(options = {}) {
315
316
  enforce: "pre",
316
317
 
317
318
  buildStart() {
318
- generateTypesFile(pagesDir, typesPath, basePath);
319
+ generateTypesFile(pagesDir, typesPath, base);
319
320
  },
320
321
 
321
322
  configureServer(server) {
322
- generateTypesFile(pagesDir, typesPath, basePath);
323
+ generateTypesFile(pagesDir, typesPath, base);
323
324
 
324
- const watchPath = `/src/pages/${dirSuffix}/`;
325
+ const watchPath = `/${dir}/`;
325
326
  server.watcher.on("all", (event, filePath) => {
326
327
  if (
327
328
  filePath.includes(watchPath) &&
328
329
  (filePath.endsWith("page.svelte") || filePath.endsWith("layout.svelte") || filePath.endsWith("404.svelte"))
329
330
  ) {
330
- generateTypesFile(pagesDir, typesPath, basePath);
331
+ generateTypesFile(pagesDir, typesPath, base);
331
332
 
332
333
  const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
333
334
  if (mod) {
@@ -360,7 +361,7 @@ export function plugin(options = {}) {
360
361
 
361
362
  load(id) {
362
363
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
363
- return generateRoutesModule(pagesDir, basePath);
364
+ return generateRoutesModule(pagesDir, base);
364
365
  }
365
366
  if (id === RESOLVED_SPA_ID) {
366
367
  return generateAppComponent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volpe/astro-svelte-spa",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Vite plugin for file-based routing with svelte5-router in Astro",
5
5
  "type": "module",
6
6
  "main": "index.js",