A TypeScript monorepo template for building Progressive Web Apps (PWA) with SvelteKit. Compatible with both Bun and npm package managers.
bun-svelte-pwa/
โโโ modules/ # Workspace modules
โ โโโ app/ # Main SvelteKit PWA application
โ โ โโโ public/ # Static assets
โ โ โโโ src/ # Source code
โ โ โ โโโ lib/ # Reusable components and assets
โ โ โ โโโ routes/ # SvelteKit routes
โ โ โ โ โโโ +layout.svelte
โ โ โ โ โโโ +page.svelte
โ โ โ โโโ app.css # Global styles
โ โ โ โโโ app.html # HTML template
โ โ โโโ tests/ # Playwright E2E tests
โ โ โโโ package.json
โ โ โโโ project.json # Nx project configuration
โ โ โโโ tsconfig.json
โ โ โโโ svelte.config.js
โ โ โโโ vite.config.ts
โ โ โโโ tailwind.config.js
โ โ โโโ playwright.config.ts
โ โโโ shared/ # Shared utilities library
โ โโโ src/
โ โโโ package.json
โ โโโ project.json # Nx project configuration
โ โโโ tsconfig.json
โโโ nx.json # Nx workspace configuration
โโโ package.json # Root package with workspace config
โโโ tsconfig.json # Root TypeScript config
Choose one of the following package managers:
Both package managers are fully supported and work identically.
npm install
npm run dev
npm run build
npm run preview
npm test
bun install
bun dev
bun run build
bun run preview
bun test
Note: All commands work identically with both
npmandbun. The development server starts athttp://localhost:5173
The monorepo uses Nx for efficient task management with caching and dependency handling. Commands work with both npm and Bun:
With npm:
npm run dev - Start development server for the app modulenpm run build - Build the app module for productionnpm run preview - Preview the production buildnpm test - Run Vitest testsnpm run test:ui - Run tests in UI modenpm run test:e2e - Run Playwright E2E testsnpm run type-check - Run TypeScript type checking across all modulesnpm run clean - Clean build artifacts from all modulesWith Bun:
bun dev - Start development server for the app modulebun run build - Build the app module for productionbun run preview - Preview the production buildbun test - Run Vitest testsbun run test:ui - Run tests in UI modebun run test:e2e - Run Playwright E2E testsbun run type-check - Run TypeScript type checking across all modulesbun run clean - Clean build artifacts from all modulesYou can also use Nx commands directly for more control:
# Run a target for a specific project
npx nx build @bun-svelte-pwa/app
npx nx type-check @bun-svelte-pwa/shared
# Run a target for all projects
npx nx run-many -t build
npx nx run-many -t type-check
# View project graph
npx nx graph
# Clear Nx cache
npx nx reset
Benefits of Nx:
To add a new module to the monorepo:
modules/:mkdir modules/your-module
With npm:
cd modules/your-module
npm init
With Bun:
cd modules/your-module
bun init
project.json file in the new module directory to configure Nx targets:{
"name": "@bun-svelte-pwa/your-module",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "modules/your-module/src",
"projectType": "library",
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"command": "tsc",
"cwd": "modules/your-module"
}
}
}
}
The template uses Tailwind CSS for styling:
modules/app/tailwind.config.js@tailwindcss/vite for optimal integrationExample:
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Click me
</button>
The project includes two types of tests:
Unit tests are located in modules/app/src/**/*.test.ts and use:
Running unit tests:
With npm:
npm test # Run tests once
npm run test:watch # Run in watch mode
npm run test:ui # Run with UI
With Bun:
bun test # Run tests once
bun run test:watch # Run in watch mode
bun run test:ui # Run with UI
Bun-specific setup:
When running tests with Bun's test runner, the project uses:
happydom.ts - Registers Happy DOM to provide browser APIs like document and windowsvelte-loader.ts - Compiles .svelte files for the Bun test runnerbunfig.toml - Configures Bun to preload these files before running testsThis ensures tests work identically with both npm/vitest and Bun's native test runner.
Playwright is configured for end-to-end testing:
modules/app/playwright.config.tsmodules/app/tests/With npm:
npm run test:e2e - Run E2E testsnpm run test:e2e:ui - Run E2E tests in UI modenpm run test:e2e:headed - Run E2E tests in headed modeWith Bun:
bun run test:e2e - Run E2E testsbun run test:e2e:ui - Run E2E tests in UI modebun run test:e2e:headed - Run E2E tests in headed modeExample test:
import { test, expect } from '@playwright/test';
test('counter increments', async ({ page }) => {
await page.goto('/');
const button = page.getByRole('button', { name: /count is/i });
await button.click();
await expect(button).toHaveText('count is 1');
});
The template includes PWA support out of the box:
To customize the PWA:
modules/app/vite.config.tsmodules/app/public/All modules are configured with TypeScript:
Feel free to submit issues and enhancement requests!
MIT