Skip to content

Commit

Permalink
feat: add offline caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm authored Jun 25, 2024
2 parents 7133bb6 + 6f85a47 commit 8e53a9a
Show file tree
Hide file tree
Showing 6 changed files with 1,898 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

dev-dist
# dependencies
node_modules
/.pnp
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
"prisma": "^4.8.1",
"typescript": "^5.4",
"vite": "^5.1.6",
"vite-node": "^1.4.0"
"vite-node": "^1.4.0",
"vite-plugin-pwa": "^0.20.0",
"workbox-window": "^7.1.0"
}
}
5 changes: 5 additions & 0 deletions packages/frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import "./index.css";
import { Link } from "@tanstack/react-router";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ErrorBoundary } from "react-error-boundary";
import { registerSW } from "virtual:pwa-register";

if ("serviceWorker" in navigator) {
registerSW({});
}

startReactDsfr({ defaultColorScheme: "system", Link: Link });

Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"paths": {
"#styled-system/*": ["./styled-system/*"],
"#components/*": ["./src/components/*"]
}
},
"types": ["vite-plugin-pwa/client"]
},
"include": ["src/**/*.tsx", "src/**/*.ts"],
"exclude": [
Expand Down
28 changes: 22 additions & 6 deletions packages/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { TanStackRouterVite } from "@tanstack/router-vite-plugin";
import wasm from "vite-plugin-wasm";

import { VitePWA } from "vite-plugin-pwa";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), TanStackRouterVite(), wasm()],
plugins: [
react(),
TanStackRouterVite(),
wasm(),
VitePWA({
devOptions: { enabled: true },
manifest: {
id: "gouv.beta.compte-rendu-vif",
orientation: "portrait",
short_name: "CR-VIF",
name: "Compte-rendu VIF",
scope: "/",
start_url: "/",
lang: "fr",
},
workbox: {
maximumFileSizeToCacheInBytes: 2097152 * 3,
globPatterns: ["**/*.{svg,woff2,js,wasm,css,html}"],
},
}),
],
envDir: "../..",
preview: {},
worker: {
format: "es",
plugins: () => [wasm()],
},
build: {
target: "esnext",
},
Expand Down
Loading

0 comments on commit 8e53a9a

Please sign in to comment.