🐛 Fix Service Worker: New hash every build (#5928)

* New hash every build

* Add release notes for PR #5928

* trigger actions

* Changed from TS to MTS

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
lelemm
2025-10-15 13:11:54 -03:00
committed by GitHub
parent 328dfae8bf
commit 96ac1292f9
3 changed files with 11 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ if [ $NODE_ENV == 'development' ]; then
ln -snf "$ROOT"/../dist/ "$DESKTOP_DIR"/service-worker
fi
yarn vite build --config ../vite.config.ts --mode $NODE_ENV $VITE_ARGS
yarn vite build --config ../vite.config.mts --mode $NODE_ENV $VITE_ARGS
if [ $NODE_ENV == 'production' ]; then
# In production, just copy the built files

View File

@@ -3,10 +3,10 @@ import path from 'path';
import { defineConfig } from 'vite';
// eslint-disable-next-line import/no-default-export
export default defineConfig(({ mode }) => {
const isDev = mode === 'development';
const outDir = path.resolve(__dirname, 'dist');
const buildHash = Date.now().toString(36);
return {
mode,
@@ -18,7 +18,8 @@ export default defineConfig(({ mode }) => {
entry: path.resolve(__dirname, 'src/plugin-service-worker.ts'),
name: 'plugin_sw',
formats: ['iife'],
fileName: () => (isDev ? 'plugin-sw.dev.js' : 'plugin-sw.[hash].js'),
fileName: () =>
isDev ? `plugin-sw.dev.js` : `plugin-sw.${buildHash}.js`,
},
sourcemap: true,
minify: isDev ? false : 'terser',

View File

@@ -0,0 +1,7 @@
---
category: Bugfix
authors: [lelemm]
---
Fix service worker to generate a new hash with every build for better caching.