diff --git a/build/sw_plugin.js b/build/sw_plugin.js index f8141920d..39cc31405 100644 --- a/build/sw_plugin.js +++ b/build/sw_plugin.js @@ -27,13 +27,12 @@ export const devSwPlugin = ({ swSrc, swDest, transformSW, alias }) => { Object.entries(alias).forEach(([source, dest]) => { esbuildAlias[source] = dest.startsWith('/') ? projectRoot + dest : dest }) - let localConfig return { name: 'dev-sw-plugin', apply: 'serve', - configResolved(config) { - localConfig = config + configResolved() { + /* no-op */ }, resolveId(id) { const name = id.startsWith('/') ? id.slice(1) : id @@ -58,13 +57,9 @@ export const devSwPlugin = ({ swSrc, swDest, transformSW, alias }) => { * https://bugzilla.mozilla.org/show_bug.cgi?id=1360870 */ async transform(code, id) { - if (id === swFullSrc) { + if (id === swFullSrc && transformSW) { const res = await esbuild.build({ entryPoints: [swSrc], - define: { - 'process.env': JSON.stringify(localConfig.define['process.env']), - 'COMMIT_HASH': JSON.stringify(localConfig.define['COMMIT_HASH']), - }, bundle: true, write: false, outfile: 'sw-pleroma.js', @@ -140,17 +135,16 @@ export const buildSwPlugin = ({ swSrc, swDest }) => { publicDir: false, build: { ...resolvedConfig.build, + lib: { + entry: swSrc, + formats: ['iife'], + name: 'sw_pleroma', + }, emptyOutDir: false, rolldownOptions: { - input: { - main: swSrc - }, - context: 'self', output: { entryFileNames: swDest, - codeSplitting: false, - format: 'iife', - } + }, }, }, configFile: false, diff --git a/vite.config.js b/vite.config.js index 9586b1aeb..a521fae49 100644 --- a/vite.config.js +++ b/vite.config.js @@ -165,6 +165,18 @@ export default defineConfig(async ({ mode, command }) => { }), ...(mode === 'test' ? [mswPlugin()] : []), ], + optimizeDeps: { + // For unknown reasons, during vitest, vite will re-optimize the following + // deps, causing the test to reload, so add them here so that it will not + // reload during tests + include: [ + 'custom-event-polyfill', + 'vue-i18n', + '@ungap/event-target', + 'body-scroll-lock', + '@kazvmoe-infra/pinch-zoom-element', + ], + }, css: { devSourcemap: true, transformer: 'lightningcss', @@ -198,6 +210,7 @@ export default defineConfig(async ({ mode, command }) => { main: 'index.html', }, output: { + inlineDynamicImports: false, entryFileNames(chunkInfo) { const id = chunkInfo.facadeModuleId if (id.endsWith(swSrc)) {