trying to use vite-pwa for SW

This commit is contained in:
Henry Jameson 2026-06-02 22:14:13 +03:00
commit 8824049f28
6 changed files with 1499 additions and 52 deletions

View file

@ -11,12 +11,11 @@ import { configDefaults } from 'vitest/config'
import { getCommitHash } from './build/commit_hash.js'
import copyPlugin from './build/copy_plugin.js'
import emojisPlugin from './build/emojis_plugin.js'
import mswPlugin from './build/msw_plugin.js'
import {
buildSwPlugin,
devSwPlugin,
swMessagesPlugin,
} from './build/sw_plugin.js'
import { VitePWA } from 'vite-plugin-pwa'
const localConfigPath = '<projectRoot>/config/local.json'
const normalizeTarget = (target) => {
@ -110,7 +109,7 @@ export default defineConfig(async ({ mode, command }) => {
},
}
const swSrc = 'src/sw.js'
const swSrc = 'src/sw-pleroma.js'
const swDest = 'sw-pleroma.js'
const alias = {
src: '/src',
@ -142,9 +141,6 @@ export default defineConfig(async ({ mode, command }) => {
// outDir: 'custom-dir', // optional, defaults to Vite's build.outDir
},
}),
devSwPlugin({ swSrc, swDest, transformSW, alias }),
buildSwPlugin({ swSrc, swDest }),
swMessagesPlugin(),
emojisPlugin(),
copyPlugin({
inUrl: '/static/ruffle',
@ -163,7 +159,24 @@ export default defineConfig(async ({ mode, command }) => {
'node_modules/.cache/stylelintcache',
),
}),
...(mode === 'test' ? [mswPlugin()] : []),
swMessagesPlugin(),
VitePWA({
strategies: 'injectManifest',
srcDir: 'src',
filename: 'sw-pleroma.js',
manifest: false,
injectRegister: null,
devOptions: {
enabled: true,
type: 'classic',
},
injectManifest: {
injectionPoint: undefined,
buildPlugins: {
vite: [swMessagesPlugin()],
},
}
}),
],
optimizeDeps: {
// For unknown reasons, during vitest, vite will re-optimize the following