From 1a9d48444c7fcae166f3570d79cddebab58ad628 Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 21 Sep 2022 19:57:32 +0200 Subject: [PATCH] cleanup: remove kit plugin --- src/index.ts | 92 +--------------------------------------------------- 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3a6a37f..33ea1e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import type { Plugin } from 'vite' -import type { VitePluginPWAAPI } from 'vite-plugin-pwa' import { VitePWA } from 'vite-plugin-pwa' import type { SvelteKitPWAOptions } from './types' import { configureSvelteKitOptions } from './config' @@ -18,96 +17,7 @@ export function SvelteKitPWA(userOptions: Partial = {}): Pl options, ) - let api: VitePluginPWAAPI | undefined - let command: 'build' | 'serve' | undefined - - const plugins = VitePWA(userOptions) - - const virtual = 'virtual:vite-pwa/sveltekit' - const resolvedVirtual = `\0${virtual}.js` - - plugins.push( - { - name: 'vite-plugin-pwa:sveltekit', - enforce: 'pre', - configResolved(viteConfig) { - if (!viteConfig.build.ssr) { - command = viteConfig.command - api = viteConfig.plugins.find(p => p.name === 'vite-plugin-pwa')?.api - } - }, - resolveId(id) { - if (id === virtual) - return resolvedVirtual - }, - load(id) { - if (id === resolvedVirtual) { - const pwaEnabled = api && !api.disabled && (command === 'build' || userOptions.devOptions?.enabled === true) - let webManifest = '' - if (pwaEnabled) { - const webManifestData = api!.webManifestData() - if (webManifestData) - webManifest = `` - } - // TODO: add missing logic - return ` -export const pwaEnabled = ${pwaEnabled}; -export function registerDevServiceWorker() { return undefined; } -export function webManifestLink() { return '${webManifest}'; } -export function registerSWScript() { return undefined; } - ` - } - }, - - /* - resolveId(id) { - if (id === '$vite-pwa/sveltekit') - return 'vite-pwa-sveltekit-pwa-enabled.js' - - if (id === '$vite-pwa/sveltekit/webmanifest') - return 'vite-pwa-sveltekit-webmanifest.svelte' - }, - load(id) { - let code: string | undefined - if (id === 'vite-pwa-sveltekit-pwa-enabled.js') { - code = command === 'serve' - ? `export const pwaEnabled = ${api && !api.disabled && userOptions.devOptions?.enabled === true}` - : `export const pwaEnabled = ${api && !api.disabled}` - } - - if (id === 'vite-pwa-sveltekit-webmanifest.svelte') { - const href = command === 'serve' - ? userOptions.devOptions?.enabled === true - ? api?.webManifestUrl - : undefined - : api?.webManifestUrl - code = href - ? `` - : '' - code = `{@html \`${escapeSvelte(code)}\`}` - } - - if (code) { - return { - code, - map: { version: 3, mappings: '', sources: [] } as any, - } - } - }, -*/ - }, - ) - - // escape curlies, backtick, \\t, \\r, \\n to avoid breaking output of {@html \`here\`} in .svelte - // function escapeSvelte(str: string): string { - // return str - // .replace(/{/g, '{') - // .replace(/}/g, '}') - // .replace(/\`/g, '`') - // .replace(/\\\\([trn])/g, ' ') - // } - - return plugins + return VitePWA(userOptions) } export * from './types'