From 73ae0164a2bfac3b62b239a76423e2765e6a014b Mon Sep 17 00:00:00 2001 From: Guilherme_F Date: Fri, 28 Jun 2024 17:37:20 +0100 Subject: [PATCH] Fixed production and started pwa support --- code/client/package.json | 1 + code/client/public/robots.txt | 2 +- code/client/src/pwa/manifest-config.ts | 22 +++++++++++++++++++++ code/client/src/pwa/pwa-config.ts | 11 +++++++++++ code/client/vite.config.ts | 27 +++++++------------------- 5 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 code/client/src/pwa/manifest-config.ts create mode 100644 code/client/src/pwa/pwa-config.ts diff --git a/code/client/package.json b/code/client/package.json index 9d14597a..b6fe61c9 100644 --- a/code/client/package.json +++ b/code/client/package.json @@ -61,6 +61,7 @@ "sass": "^1.77.0", "typescript": "^5.5.2", "vite": "^5.2.11", + "vite-plugin-pwa": "^0.20.0", "vite-tsconfig-paths": "^4.3.2", "vitest": "^1.6.0" } diff --git a/code/client/public/robots.txt b/code/client/public/robots.txt index 5537f073..7f4904e3 100644 --- a/code/client/public/robots.txt +++ b/code/client/public/robots.txt @@ -1,3 +1,3 @@ # https://www.robotstxt.org/robotstxt.html User-agent: * -Disallow: \ No newline at end of file +Allow: / \ No newline at end of file diff --git a/code/client/src/pwa/manifest-config.ts b/code/client/src/pwa/manifest-config.ts new file mode 100644 index 00000000..86f3e0d7 --- /dev/null +++ b/code/client/src/pwa/manifest-config.ts @@ -0,0 +1,22 @@ +import {ManifestOptions} from "vite-plugin-pwa"; + +const manifestConfig : Partial = { + name: 'NoteSpace', + short_name: 'NoteSpace', + description: 'A multiplatform note management and sharing app', + theme_color: '#ffffff', + icons: [ + { + src: '/assets/icon.png', + sizes: '192x192', + type: 'image/png', + }, + { + src: '/assets/icon.png', + sizes: '512x512', + type: 'image/png', + }, + ], +} + +export default manifestConfig; \ No newline at end of file diff --git a/code/client/src/pwa/pwa-config.ts b/code/client/src/pwa/pwa-config.ts new file mode 100644 index 00000000..b367228f --- /dev/null +++ b/code/client/src/pwa/pwa-config.ts @@ -0,0 +1,11 @@ +import {VitePWAOptions} from "vite-plugin-pwa"; +//import manifestConfig from "./manifest-config"; + +const pwaConfig : Partial = { + registerType: 'autoUpdate', + //manifest: manifestConfig, + //devOptions: { + // enabled: true, + //} +} +export default pwaConfig; \ No newline at end of file diff --git a/code/client/vite.config.ts b/code/client/vite.config.ts index 5ffc1750..4f94fc9b 100644 --- a/code/client/vite.config.ts +++ b/code/client/vite.config.ts @@ -5,6 +5,8 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import tsconfigPaths from 'vite-tsconfig-paths'; import { config } from 'dotenv'; +import {VitePWA} from "vite-plugin-pwa"; +import pwaConfig from "./src/pwa/pwa-config"; // Load environment variables from .env file config(); @@ -14,26 +16,11 @@ export default defineConfig({ server: { port: Number.parseInt(process.env.VITE_PORT) || 5173, }, - plugins: [tsconfigPaths(), react()], - build: { - // Enable sourcemaps if needed - // sourcemap: true, - rollupOptions: { - output: { - manualChunks: (id: string) => { - if (id.includes('node_modules')) { - if (id.includes('react')) return 'react'; - if (id.includes('slate')) return 'slate'; - return 'vendor'; - } - if (id.includes('src')) return 'app'; - }, - entryFileNames: 'assets/[name].js', - chunkFileNames: 'assets/[name].js', - assetFileNames: 'assets/[name].[ext]', - }, - }, - }, + plugins: [ + tsconfigPaths(), + react(), + VitePWA(pwaConfig) + ], test: { globals: true, alias: {