Bot releases are visible (Hide)
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
Thanks @DuCanhGH! - fix(cjs): fixed CommonJS builds crashing
chunkFileNames
, otherwise Rollup would always use ".js" for all the chunks. What in the world.Updated dependencies [0bb9635
, bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
bd75087
]:
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
b80b988
Thanks @DuCanhGH! - feat(vite): added @serwist/vite
This is a fork of vite-plugin-pwa
, but it has undergone a major refactor so as to meet our use case. One can notice the obvious lack of features in comparison to vite-plugin-pwa
.
At the moment, only base Vite and SvelteKit are supported. Support for some other frameworks, such as Astro, Nuxt, and Solid.js, will land soon.
Currently, @serwist/vite
and its SvelteKit integration do not support development mode. This is because of two reasons:
vite-plugin-pwa
's way of supporting dev was... seemingly unnecessarily bloated in my opinion. I hold the belief that having a separate "dev-sw.js" is not the way to go. Rather, I want to directly bundle swSrc
. It's just that I've not figured out a way to do so. If that's not possible, perhaps we can consider their way of doing it again.To get started:
// src/sw.ts
import type { PrecacheEntry } from "@serwist/precaching";
import { installSerwist } from "@serwist/sw";
import { defaultCache } from "@serwist/vite/worker";
declare const self: ServiceWorkerGlobalScope & {
// Change this attribute's name to your `injectionPoint`.
__SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
};
installSerwist({
precacheEntries: self.__SW_MANIFEST,
skipWaiting: true,
clientsClaim: true,
navigationPreload: true,
runtimeCaching: defaultCache,
});
// vite.config.{ts,js}
import { serwist } from "@serwist/vite";
import { defineConfig } from "vite";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// other plugins...
serwist({
swSrc: "src/sw.ts",
swDest: "sw.js",
globDirectory: "dist",
injectionPoint: "self.__SW_MANIFEST",
rollupFormat: "iife",
}),
],
});
// App.ts
const registerSerwist = async () => {
// dev mode is not supported at the moment.
if (import.meta.env.DEV) return;
const serwist = await getSerwist();
if (serwist) {
serwist.addEventListener("installed", () =>
console.log("Serwist installed!"),
);
await serwist.register();
}
};
registerSerwist();
// src/service-worker.ts
/// <reference no-default-lib="true"/>
/// <reference lib="esnext" />
/// <reference lib="webworker" />
/// <reference types="@sveltejs/kit" />
import type { PrecacheEntry } from "@serwist/precaching";
import { installSerwist } from "@serwist/sw";
import { defaultCache } from "@serwist/vite/worker";
declare const self: ServiceWorkerGlobalScope & {
// Change this attribute's name to your `injectionPoint`.
__SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
};
installSerwist({
precacheEntries: self.__SW_MANIFEST,
skipWaiting: true,
clientsClaim: true,
navigationPreload: true,
runtimeCaching: defaultCache,
});
// vite.config.{ts,js}
import { serwist } from "@serwist/vite/integration-svelte";
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
sveltekit(),
serwist({
// dev mode is not supported at the moment.
disable: process.env.NODE_ENV === "development",
}),
],
});
// +layout.svelte
$effect(() => {
const registerSerwist = async () => {
// dev mode is not supported at the moment.
if (import.meta.env.DEV) return;
const serwist = await getSerwist();
if (serwist) {
serwist.addEventListener("installed", () =>
console.log("Serwist installed!"),
);
await serwist.register();
}
};
registerSerwist();
});
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago
Published by github-actions[bot] 10 months ago