A lightweight Svelte 5 library for building file-based applications with routing, SSG (Static Site Generation), and advanced URL management.
npm install svelte-fileapp
import { 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 segment
import { 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'],
})
bootstrapApp(AppComponent, targetId?, initFn?)Bootstraps a Svelte application with smart hydration support.
UrlParam Classget(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)UrlHash ClassgetAll() - 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 widthisSmallMenu - Writable store for responsive menu stateThe library supports three app modes:
Mode is automatically detected from:
app_mode<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 lint
MIT
Contributions are welcome! Please feel free to submit a Pull Request.