A lightweight Svelte 5 library for building file-based applications with routing, SSG (Static Site Generation), and advanced URL management.
- π File-based Routing - Simple and intuitive routing system with hash or history mode
- π¦ Static Site Generation - Built-in SSG support with jsonjsdb integration
- π Advanced URL Management - Comprehensive URL parameters and hash handling
- π― App Bootstrap - Smart hydration and mounting for SPA and static apps
- π± Browser Utilities - Device detection and responsive helpers
- β‘ Vite Plugins - Custom Vite plugins for optimization
npm install svelte-fileappimport { bootstrapApp } from 'svelte-fileapp'
import App from './App.svelte'
// Simple bootstrap
await bootstrapApp(App)
// With custom target and initialization
await bootstrapApp(App, 'app', async () => {
// Your initialization logic
console.log('App initializing...')
})import { UrlParam, UrlHash } from 'svelte-fileapp'
// Get URL parameters
const value = UrlParam.get('search')
// Set URL parameters
UrlParam.set('filter', 'active')
// Delete parameters
UrlParam.delete('filter')
// Reset all parameters
UrlParam.reset()
// Get all parameters
const allParams = UrlParam.getAllParams()
// Hash management
const currentHash = UrlHash.getAll()
const level1 = UrlHash.getLevel1() // First segment
const level2 = UrlHash.getLevel2() // Second segmentimport { router } from 'svelte-fileapp'
// Navigate programmatically
router.navigate('/home')
// Use in HTML with helper
window.goToHref(event, '/about')import {
isMobile,
isFirefox,
hasTouchScreen,
isSmallMenu,
} from 'svelte-fileapp'
if (isMobile) {
// Mobile-specific logic
}
// Reactive store for responsive layouts
isSmallMenu.subscribe(isSmall => {
console.log('Small menu:', isSmall)
})// vite.config.ts
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import {
updateRouterIndex,
htmlReplace,
spaHtmlOptimizations,
getAliases,
} from 'svelte-fileapp'
export default defineConfig({
plugins: [
svelte(),
updateRouterIndex(),
htmlReplace(),
spaHtmlOptimizations(),
],
resolve: {
alias: getAliases(import.meta.url),
},
})import { generateStaticSite } from 'svelte-fileapp'
await generateStaticSite({
routes: ['/', '/about', '/contact'],
outDir: 'dist',
})import { generateJsonjsdbStaticSite } from 'svelte-fileapp'
await generateJsonjsdbStaticSite({
dbPath: './data',
outDir: 'dist',
entities: ['posts', 'users'],
})Bootstraps a Svelte application with smart hydration support.
- AppComponent: The root Svelte component
- targetId: Target element ID (default: 'app')
- initFn: Optional async initialization function
get(key)- Get URL parameter valueset(key, value)- Set URL parameterdelete(key)- Delete URL parameterreset()- Reset all parametersgetAllParams()- Get all parameters as objectgetAppMode()- Get current app mode (spa/static_render/check_db)
getAll()- Get complete hash valuegetLevel1()- Get first segment of hashgetLevel2()- Get second segment of hashdefault- Default hash value ('homepage')
isFirefox- Boolean for Firefox detectionisMobile- Boolean for mobile detectionhasTouchScreen- Boolean for touch screen detectiondocumentWidth- Current document width
isSmallMenu- Writable store for responsive menu state
The library supports three app modes:
- SPA (default) - Single Page Application with hash routing
- static_render - Static site generation mode
- check_db - Database check mode
Mode is automatically detected from:
- URL parameter
app_mode - Meta tag
<meta app-mode="static">
import {
getInitialPage,
getInitialComponent,
updateRouteComponent,
} from 'svelte-fileapp'
// Get initial page based on static mode
const initialPage = getInitialPage(routerIndex, '_loading')
// Get component with hydration support
const component = getInitialComponent(routerIndex, initialPage, '_loading')# Install dependencies
npm install
# Build library
npm run build
# Run tests
npm test
# Lint code
npm run lintMIT
Contributions are welcome! Please feel free to submit a Pull Request.